繁体   English   中英

如何在XML Android中的Button内调整图标的大小或缩放

[英]How to resize OR scale icon inside Button in xml android

我有这个简单的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实现此目的: http : //developer.android.com/intl/es/tools/help/draw9patch.html

有两种可能的方法:

1)使用不同尺寸的可绘制对象,如建议的Agustin Sovoplas。

2)创建带有2个视图的水平LinearLayout-将图像设置为背景的View和具有相应文本的TextView。 之后,为此LinearLayout设置OnClickListener并像常规按钮一样对其进行处理。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM