例如,我有一個ListView裏面,每一行的數據是這樣的如何對齊文本android的文本視圖
Name: Mr.ABC
Address: Flat A, 25/F, Block 2,
USA....
Gender: Male
Hobbies: Football, Baseball.....
.....
而且上面是它目前如何看待喜歡,我用4文本視圖來表示每個數據
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="9"
android:orientation="vertical"
android:paddingLeft="5dp" >
<TextView
android:id="@+id/resultName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp" />
<TextView
android:id="@+id/resultLang"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp" />
<TextView
android:id="@+id/resultType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp" />
<TextView
android:id="@+id/resultOrg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp" />
<TextView
android:id="@+id/resultYear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp" />
</LinearLayout>
問題是我該如何對齊這樣的文本?
Name: Mr.ABC
Address: Flat A, 25/F, Block 2,
USA....
Gender: Male
Hobbies: Football, Baseball.....
.....
感謝您的幫助
更新
<TableLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="9"
android:paddingLeft="5dp"
android:shrinkColumns="*"
android:stretchColumns="*" >
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_weight="1"
android:text="@string/search_name"
android:textSize="16sp" />
<TextView
android:id="@+id/resultName"
android:layout_weight="1"
android:textSize="16sp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_weight="1"
android:text="@string/search_lang"
android:textSize="16sp" />
<TextView
android:id="@+id/resultLang"
android:layout_weight="1"
android:textSize="16sp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_weight="1"
android:text="@string/search_type"
android:textSize="16sp" />
<TextView
android:id="@+id/resultType"
android:layout_weight="1"
android:textSize="16sp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_weight="1"
android:text="@string/search_org"
android:textSize="16sp" />
<TextView
android:id="@+id/resultOrg"
android:layout_weight="1"
android:textSize="16sp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_weight="1"
android:text="@string/search_yr"
android:textSize="16sp" />
<TextView
android:id="@+id/resultYear"
android:layout_weight="1"
android:textSize="16sp" />
</TableRow>
</TableLayout>
以上是更新的代碼,但問題是,既然是ListView和我發現左側寬度不相等。這是像例如
Name: Mr.ABC
Address: Flat A, 25/F, Block 2,
USA....
Gender: Male
Hobbies: Football, Baseball.....
.....
Name: Mr.Asfsafasfdfsd
Address: Flat V, 25/F, Block 2,
USA....
Gender: Female
Hobbies: Basketball.....
.....
Name: Mr.WQWRWEE
Address: Flat V, 25/F, Block 2,
USA....
Gender: Male
Hobbies: Baseball.....
.....
你可以使用8個textviews。我不認爲你可以只使用4個文字瀏覽 – novic3
是和使用重量佈局,但我怎樣才能定義重量?謝謝 – user782104
例如1名爲ABC,ABC先生爲9名?但是如果設備屏幕太小而無法顯示名稱呢? – user782104