![](/img/trans.png)
[英]Textview under ImageView that is resizable in Listview Item layout?
[英]Trouble with listview row layout that have imageview, textview and a button?
我設計了以下布局。 除了 wxga 屏幕外,在所有尺寸的模擬器上都能很好地工作。 我也在我的 tegra 2 供電的 Toshiba AC100 上嘗試過,但按鈕沒有對齊到屏幕的右側,而是縮小並顯示在 textview 的右側。它在我兄弟的 HVGA xperia mini ST15i 上看起來不錯。
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow android:id="@+id/tableRow">
<ImageView android:id="@+id/image"
android:layout_width="32dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="5dp"
android:layout_height="32dp"
android:focusable="false"
android:focusableInTouchMode="false" />
<TextView android:id="@+id/text"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:padding="10dp"
android:focusable="false"
android:focusableInTouchMode="false" />
<Button android:id="@+id/button"
android:layout_width="60dp"
android:layout_alignParentRight="true"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/button"
android:focusable="false"
android:focusableInTouchMode="false" />
</TableRow>
</TableLayout>
我用 imageview、textview 和按鈕找出列表視圖的布局。 它在不同的屏幕方向和尺寸下都能很好地工作。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:id="@+id/relativeLayout"
android:layout_height="wrap_content">
<ImageView android:id="@+id/drawable_icon"
android:layout_width="36dp"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:layout_alignParentLeft="true"
android:layout_height="36dp"
android:focusable="false"
android:focusableInTouchMode="false" />
<TextView android:id="@+id/text"
android:layout_toRightOf="@id/drawable_icon"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_marginRight="65dp"
android:focusable="false"
android:focusableInTouchMode="false" />
<Button android:id="@+id/button"
android:layout_width="60dp"
android:layout_alignParentRight="true"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:text="@string/buttonText"
android:focusable="false"
android:focusableInTouchMode="false" />
</RelativeLayout>
也許您可以將 LinearLayout 用於 ImageView、TextView 和 Button 的父級。 在 LinearLayout 中使用水平方向。 如果想讓孩子在所有情況下都可見,可以在ImageView、TextView、Button中添加android:layout_weight="1"屬性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.