我想顯示在ListView行的一些文本與以下定位:如何對齊佈局中的文本中的Android
Mike 10pt $1,233,500
Mike2 200pt $1,2,500
Holly 10pt $4500
但是,當我嘗試,我得到了這個:
Mike 10pt $1,233,500
Mike2 200pt $12,500
Holly 10pt $4500
我的佈局文件如下。我究竟做錯了什麼?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:background="@drawable/dl005_textfield_selected"
android:paddingBottom="5dp" >
<TextView
android:id="@+id/Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Mike"
android:layout_weight="1"
android:textColor="#888888" />
<TextView
android:id="@+id/score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:gravity="right"
android:text="10pt"
android:textColor="#3498db" />
<TextView
android:id="@+id/myid"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:text="$1,233,500"
android:textStyle="bold"
android:textSize="18sp"
android:layout_weight="1"
android:gravity="right"
android:textColor="#3498db" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
</LinearLayout>
你考慮過使用['TableLayout']嗎?看起來這將是完美的佈局。從文檔:「將子項排列成行和列的佈局。」您可以根據需要將單元格文本對齊方式設置爲左/右。 – stkent 2015-04-06 03:29:59
使用'TableLayout'是一種推薦的方法,當你使用水平佈局的weight屬性時,你的linearlayout的使用是'width'必須是'0dp'。 – Piyush 2015-04-06 03:50:35