ListView中排造型 - 左对齐文本,右对齐图标 [英] ListView row styling - left aligned text, and right-aligned icon
问题描述
我试图让ListView的行如下所示:
I'm trying to get ListView row to look like the following:
| Text-Text-Text <ImageButton> |
随着ImageButton的捕捉到右边缘。我怎样才能做到这一点?下面是当前布局code我使用。我究竟做错了什么?
With the imagebutton snapped to the right edge. How can I do this? Here's the current layout code I'm using. What am I doing wrong?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layercontainer"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#699">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="left">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="YO HOW SI IT GOESSDA" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="right">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/trash" />
</LinearLayout>
</LinearLayout>
我的code目前生产的:
My code currently produces this:
推荐答案
第1步:使用 RelativeLayout的
基础
第二步:把你的的ImageButton
具有安卓layout_alignParentRight =真正的
第三步:把你的的TextView
已具有安卓layout_alignParentLeft =真正的
,安卓:layout_toLeftOf =...
(其中 ...
是ID的的ImageButton
),也许还有一些其他的 RelativeLayout.LayoutParams
值垂直对齐
Step #3: Put your TextView
has having android:layout_alignParentLeft="true"
, android:layout_toLeftOf="..."
(where ...
is the ID of your ImageButton
), and perhaps some other RelativeLayout.LayoutParams
value for vertical alignment
这篇关于ListView中排造型 - 左对齐文本,右对齐图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!