/ / Android:TableLayoutは最初の列を右に、2番目を左に揃える-android、sdk、tablelayout、tablerow

Android:TableLayout最初の列を右揃え、2番目の左揃え - Android、sdk、tablelayout、tablerow

そのような何かを得るために私は何をしなければなりません:

画像サンプル

HTMLでは問題なく実行できますが、Androidではどうですか?

回答:

回答№1は2
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>

回答№2の場合は1
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>

回答№3の場合は0

あなたの列で TableLayout あなたが使用している必要があります TextView コンテンツを表示します。

最初のコラムではこれを試してください、

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:text="Key"
android:textColor="@android:color/black"/>

そして2列目はこれを試してください、

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Value"
android:textColor="@android:color/black"/>