【问题标题】:How both text and image take place in a button文本和图像如何在按钮中发生
【发布时间】:2012-07-03 09:10:29
【问题描述】:

我试图让布局看起来像它

看起来有点像按钮类型。如何在按钮中同时实现文本和图像?

【问题讨论】:

    标签: android image button text


    【解决方案1】:

    将您的自定义按钮创建为:

    步骤 1: 在 res/drawable/button_background.xml 中创建一个 Button 可绘制形状 xml:

    <?xml version=”1.0″ encoding=”UTF-8″?>
    <shape xmlns:android=”http://schemas.android.com/apk/res/android”>
    <solid android:color=”#F000″/>
    <stroke android:width=”1px” android:color=”#BB000000″ />
    <padding
    android:left=”10dp”
    android:top=”7dp”
    android:right=”10dp”
    android:bottom=”7dp”
    />
    <corners
    android:bottomRightRadius=”5dp”
    android:bottomLeftRadius=”5dp”
    android:topLeftRadius=”5dp”
    android:topRightRadius=”5dp”
    />
    <gradient
    android:angle=”90″
    android:startColor=”#777″
    android:centerColor=”#777″
    android:endColor=”#BBB”
    android:type=”linear”
    />
    
    </shape>
    

    第 2 步: 将主 Button xml 布局添加为:

    <Button android:id="@+id/btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Facebook"
            android:drawableLeft="@drawable/leftimg"
            android:drawableRight="@drawable/rightimg"
            android:padding="15dip"
           android:background="@drawable/button_background"/>
    

    【讨论】:

    • 这里 android:drawableRight="@drawable/rightimg" 不会使图像完全正确
    • @SidratulMuntaha : 然后从布局中删除填充 android:right=”10dp”
    【解决方案2】:

    你可以在你的按钮android:drawableLeft="@drawable/your_icon"中做到这一点

    【讨论】:

    • 你的意思是我需要在其背景中实现一个图像?
    • 是的,你也可以给 android:drawableRight="@drawable/arrow"
    猜你喜欢
    • 2018-02-08
    • 2013-05-20
    • 2011-06-16
    • 1970-01-01
    • 1970-01-01
    • 2018-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多