您是否需要在最長名稱後面開始的值?或者只是爲了能夠顯示最長的名字?那麼我會建議(並在類似的問題中)沒有使用LinearLayout,而是使用RelativeLayout。
在那裏你會定義兩個TextViews,其中一個會在右邊有重力。從我的代碼中可以看出,正確的字段總是相同的大小,對嗎?所以,根據這個調整它,讓剩下的空間可以被填滿。 我的一個例子佈局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_selector"
android:orientation="horizontal"
android:padding="3dip" >
<!-- Name-->
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textColor="#040404"
android:typeface="sans"
android:textSize="20dip"
android:text="Name"
android:textStyle="bold"/>
<!-- Amount -->
<TextView
android:id="@+id/amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="right"
android:layout_marginRight="5dip"
android:text="money"
android:textSize="20dip"
android:textColor="#FF8B1500"
android:textStyle="bold"
/>
</RelativeLayout>
,因爲它需要和左留給姓名權的TextView填充儘可能多的空間。
希望我幫忙給個主意!
來源
2012-08-24 14:20:55
Ore
如何使用雙列gridview,其中一列的所有行的寬度相同。下面是關於如何控制GridView中列寬的建議:http://stackoverflow.com/questions/985153/how-to-make-a-gridview-stretchable-in-android-to-expand-the-column-width -去任何 –