Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在xml android中调整或缩放按钮内的图标_Android_Xml - Fatal编程技术网

如何在xml android中调整或缩放按钮内的图标

如何在xml android中调整或缩放按钮内的图标,android,xml,Android,Xml,我有这个简单的xml代码,如何调整图像大小到大尺寸或小尺寸内的按钮,我需要改变它只是使用xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> &

我有这个简单的xml代码,如何调整图像大小到大尺寸或小尺寸内的按钮,我需要改变它只是使用xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <Button
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:text="some text"
        android:drawableLeft="@drawable/image"
       />
</LinearLayout>

试试这个

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

         <FrameLayout 
                android:layout_width="match_parent"
                android:layout_height="50dp">

                <Button
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:text="some text" 
                    android:paddingRight="28dp"          
                   />
                <View
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:background="@drawable/bg.png"
                    android:layout_gravity="right|center_vertical"  
                    android:marginRight="8dp"                      
                   />
         </FrameLayout>
</LinearLayout>


您可以使用Draw 9-patch来实现这一点:

有两种可能的方法:

1) 使用不同尺寸的抽绳,如Agustin Sovolas建议的


2) 创建具有两个视图的水平线性布局-将图像设置为背景的视图和具有相应文本的文本视图。之后,为该线性布局设置OnClickListener,并将其作为常规按钮进行处理。

您能解释一下内部“大尺寸”或“小尺寸”是什么意思吗?也许可以添加一个小的绘图?我的意思是我想让图像看起来更小,换句话说,我想改变图像的大小,比如宽度和高度这个制作按钮在图像上方,而不是这样,我的意思是如何在按钮标签的文本旁边放置图标看看这个链接有“按钮图标”如何调整这个“按钮图标”的大小??只需将50dp填充添加到按钮文本中我做了android:drawablePadding=“50dp”,这不会调整图标大小,这会在图标周围留出50dp的空间并按下文本如果您真的想自定义可绘制的大小,您应该按照我建议的方式进行。“android:drawableLeft”的默认实现不提供可调整大小的功能,因为您希望您的建议不会像我希望的那样工作,按钮出现在图像上方,但感谢您的帮助,我发现答案是使用文本和图像进行线性布局此工作很好,外观相同按钮:)查看此链接有“按钮图标”如何使用xml调整此“按钮图标”的大小??为每个密度使用不同的绘图尺寸。这就是我要找的第二条路,谢谢:)