0

我有一个 ListView,上面有几个按钮(宽度是 fill_parent)。该按钮包含左侧的图标和右侧的文本。问题是每当我将手指放在按钮上时,绿色背景只会覆盖文本的长度。有没有让绿色覆盖整个按钮?

假设这是文本视图中的一个按钮,其中@ 是图标,text是文本。

[@ text     ]

当我在按钮上移动手指时,只有这么多被绿色覆盖:

[#####|     ]
4

1 回答 1

0

您不应该将其用作在按钮上实现图标/文本的手段。

尝试这样的事情:

<LinearLayout android:id="@+id/descriptiveName"
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
android:orientation="horizontal" 
android:layout_gravity="center_horizontal" >

<ImageView android:id="@+id/btnIcon"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:src="@drawable/img" 
    android:layout_gravity="center_vertical"/>

<TextView android:id="@+id/btnText" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:text="text"
    android:textColor="#6B6B6B"/>

以与按钮相同的方式获取对 LinearLayout 的引用,并且您也可以以相同的方式为其设置 onClick 侦听器。

您可以为 LinearLayout 添加背景并使其成为选择器,使其在视觉上看起来也像一个按钮。

于 2012-05-31T02:02:36.257 回答