【问题标题】:Android slider drawer custom icon positionAndroid滑块抽屉自定义图标位置
【发布时间】:2015-12-29 19:47:51
【问题描述】:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >

<SlidingDrawer
    android:id="@+id/drawer"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:content="@+id/content"
    android:handle="@+id/handle"
    android:orientation="horizontal"
    android:rotation="180" >

    <ImageView
        android:id="@id/handle"
        android:layout_width="50dip"
        android:layout_height="50dip"
        android:rotation="180"
        android:src="@drawable/ic_launcher" />

    <LinearLayout
        android:id="@id/content"
        android:layout_width="250dp"
        android:layout_height="fill_parent"
        android:background="#0000ff"
        android:orientation="vertical"
        android:rotation="180" >

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Big Big Button" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Big Big Button" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Big Big Button" />
    </LinearLayout>
</SlidingDrawer>

我想改变图标位置,从左到右放在最上面

有谁能告诉我如何在 android 滑块抽屉上设置这个自定义图标位置>

提前致谢

http://i.stack.imgur.com/q8dz2.png

【问题讨论】:

  • 你好,我可以帮你,但是添加xml文件和一些图纸,截图告诉我你想要的layot是什么
  • 是的,先生,请检查该图像并解决我的问题..我想更改放在顶部的图像位置
  • 如果您希望我们帮助您,我们需要查看滑动抽屉的 xml。 (关键词帮助)
  • 好的,现在添加一个 xml 文件,我会用它作为答案;-)
  • 是的,先生,我复制了 xml 文件...请帮助我

标签: android android-layout slider android-xml


【解决方案1】:

看看你的按钮:

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Big Big Button" />

您至少可以通过四种方式为其设置图标(如本图所示):

您只需要指定Drawable 的位置即可。

  • 文字左侧:

    android:drawableLeft="@mipmap/ic_launcher"
    
  • 文字右侧:

    android:drawableRight="@mipmap/ic_launcher"
    
  • 在顶部,下面的文字:

    android:drawableTop="@mipmap/ic_launcher"
    
  • 在底部,上面的文字:

    android:drawableBottom="@mipmap/ic_launcher"
    

您只需在按钮布局中添加这些可能的行之一。

当然对于一个按钮,你可以添加多个drawable。

注意:另请阅读: http://developer.android.com/guide/topics/ui/controls/button.html

希望对你有帮助

编辑:我以前没有使用过SlidingDrawer,所以我无法识别问题出在哪里,但你总是可以做这样的把戏

    <Button
        android:id="@+id/one"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=""
        android:drawableTop="@mipmap/ic_launcher"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/handle"
        android:background="#0000ff"
        />

这是一个带有您想要的图像和“透明”背景的按钮。 现在试试看,我会寻找另一种解决方案;-)

解决方案:请尝试以下代码:

<SlidingDrawer
    android:id="@+id/drawer"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:content="@+id/content"
    android:handle="@+id/handle"
    android:orientation="horizontal"
    android:rotation="180" >

    <ImageView
        android:id="@id/handle"
        android:layout_width="50dip"
        android:layout_height="50dip"
        android:rotation="180"
        android:src="@mipmap/ic_launcher" />

    <LinearLayout
        android:id="@id/content"
        android:layout_width="250dp"
        android:layout_height="fill_parent"
        android:background="#0000ff"
        android:orientation="vertical"
        android:rotation="180" >

        <ImageView
            android:id="@id/handle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@mipmap/ic_launcher" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Big Big Button" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Big Big Button" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Big Big Button" />
    </LinearLayout>
</SlidingDrawer>
</LinearLayout>

如果您还有任何问题,请随时提问

【讨论】:

  • 先生,我想更改滑块抽屉图标的位置。不在按钮先生..请你解决我的问题
  • 先生,我想要图标的滑动抽屉位置的句柄。请帮帮我
  • 用这个改变你现有的按钮之一
  • 我使用了你的代码..但它像图像一样进入按钮......但我想要sliderdrawer处理程序图标位置先生.....sliderdrawer就像一个导航先生..
  • 我想使用带有活动的导航。我正在使用滑块抽屉
【解决方案2】:

滑动抽屉已弃用,而且很难使用,但我做了一个替换。唯一的问题是它不像滑动抽屉那样滑动,但它确实会出现和消失。这是 XML 部分:

 <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:orientation="vertical" >




        <RelativeLayout
            android:layout_width="match_parent"
            android:background="#acacac"
            android:layout_height="100dp"

            android:id="@+id/etc"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true">


            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Menu"
                android:id="@+id/bMenu"
                android:layout_alignParentBottom="true"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true"

                android:textColor="#FFFFFF"
                android:textSize="30sp"


                android:background="@drawable/button_shape_1"

                />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/linearLayout"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_above="@+id/etc"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:visibility="gone"
            android:id="@+id/menuContent">

            //content

        </RelativeLayout>

    </RelativeLayout>
</FrameLayout>

这将默认(复制/粘贴)不显示(一半)

它必须是一个框架布局,因为它们允许项目被放置在彼此之上(即根元素)

代码部分:

  RelativeLayout menuContent;
    Button showMenu;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.game);

    menuContent = (RelativeLayout) findViewById(R.id.menuContent);
    showMenu = (Button) findViewById(R.id.bMenu);
    showMenu.setOnClickListener(this);
}

boolean menuActive = false;

@Override
public void onClick(View v) {
    switch (v.getId()){
        case R.id.bMenu:
            if(menuActive){
                menuActive = false;
                menuContent.setVisibility(View.GONE);
            }else if(!menuActive){
                menuActive = true;
                menuContent.setVisibility(View.VISIBLE);
            }
        break;
    }
}

这是从我的一个最新游戏的一部分中复制出来的,所以如果它不能按原样运行,请告诉我,我会看看它

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-13
    • 2023-04-11
    • 2017-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-20
    相关资源
    最近更新 更多