Tôi phải làm gì để có được một cái gì đó như thế:Android: TableLayout sắp xếp cột đầu tiên bên phải, thứ hai rời
tôi có thể làm điều đó mà không vấn đề trong HTML nhưng làm thế nào trong Android?
Tôi phải làm gì để có được một cái gì đó như thế:Android: TableLayout sắp xếp cột đầu tiên bên phải, thứ hai rời
tôi có thể làm điều đó mà không vấn đề trong HTML nhưng làm thế nào trong Android?
Trong các cột của TableLayout
bạn phải đang sử dụng TextView
để hiển thị nội dung.
Vì vậy, cho cột đầu tiên thử loại này,
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:text="Key"
android:textColor="@android:color/black"/>
và cho cột thứ hai cố gắng này,
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Value"
android:textColor="@android:color/black"/>
Nó hoạt động, Cảm ơn. Nhưng các ô không bằng chiều rộng (chúng phải là 50% (đầu tiên) và 50% (giây)). –
@DarioRossi Các mã được hiển thị bởi Venky là hoàn hảo. Vấn đề trong mã của cô ấy là gì? –
Use TextViews and gravity
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="key" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:text="value" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="More key" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:text="More value" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="Even more key" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:text="Even more value" />
</TableRow>
</TableLayout>
nó hoạt động. nhưng có một vấn đề khác. Các ô trong bảng phải bằng với chiều rộng (giả sử 50%) nhưng trên thực tế chúng có 33% (đầu tiên) và 66% (thứ hai). –
Viết TextView đầu tiên wight = 1 và TextView wight thứ hai = 2 – Venky
Write first TextView wight=1 and second TextView wight=2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="key" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="left"
android:text="value" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="More key" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="left"
android:text="More value" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="Even more key" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="left"
android:text="Even more value" />
</TableRow>
</TableLayout>
</LinearLayout>
tôi không thể nhìn thấy hình ảnh của bạn vì ristriction sao chép xml của bạn ở đây. Vì vậy, có thể có được ý tưởng –