当按钮大于文本时,文本左侧的图像

时间:2016-03-04 09:52:51

标签: android

我想创建一个按钮,即使按钮比文本大,如下所示,文本左侧仍然是图像:

enter image description here

当然,我可以使用

android:drawableLeft="@android:drawable/image"

然后图像对齐到按钮的左侧而不是文本的左侧。

2 个答案:

答案 0 :(得分:0)

试试这个:

你也可以

android:weightSum="2"

或调整layout_weight

<LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    <ImageView
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="30dp"
        android:layout_gravity="start"
        android:background="@drawable/image"/>
    <TextView
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="30dp"
        android:padding="5dp"
        android:gravity="center_vertical"/>
</LinearLayout>

答案 1 :(得分:0)

在您的 XML 布局中尝试这些: -

<LinearLayout
        android:layout_width="match_parent"
        android:gravity="center"
        android:background="@android:color/black"//PUT HERE BUTTON BACKGROUND RESOURCE
        android:orientation="horizontal"
        android:padding="10dp"
        android:layout_height="wrap_content">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/age_icon"//PUT HERE YOURS IMAGE
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Text is here"
            android:textColor="@android:color/white"
            />


    </LinearLayout>