0

我有一个表,旨在显示一个名称后跟一个值。名称应出现在行的左侧,值应出现在右侧。这是一个例子:

表格示例

这是我的XML代码:

<TableRow>
    <TextView android:id="@+id/property_type_label"
        android:text="@string/property_type_label"
        android:padding="3dip" />
    <TextView android:id="@+id/property_type"
        android:text="@string/property_type"
        android:gravity="right"
        android:padding="3dip" />
</TableRow>

<View
    android:layout_height="2dip"
    android:background="#FF909090" />
</TableLayout>

问题是我无法查看与辅助文件关联的TextView字符串TableRow。理想情况下,存在一个不涉及大量手动操作的解决方案padding。另外,android:layout_gravity="right"也没有解决这个问题。

4

4 回答 4

1

在文本视图中使用 layout_weight 。试试这个

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<TableRow>
<TextView android:id="@+id/property_type_label"
    android:text="@string/property_type_label"
    android:layout_weight="1" />


<TextView android:id="@+id/property_type"
     android:text="@string/property_type"
    android:layout_weight="1" 
   />
 </TableRow>

<View
   android:layout_height="2dip"
   android:background="#FF909090" />

 </TableLayout>

希望这个答案对你朋友有帮助:)

于 2014-11-26T07:27:10.753 回答
1

高度宽度添加到TableRow并使用weight,如下所示:

<TableRow android:layout_width="match_parent"
          android:layout_height="match_parent">
        <TextView android:id="@+id/property_type_label"
                  android:text="@string/property_type_label"
                  android:padding="3dip" android:layout_weight="1"/>
        <TextView android:id="@+id/property_type"
                  android:text="@string/property_type"
                  android:gravity="right"
                  android:padding="3dip" android:layout_weight="1"/>
</TableRow>
于 2014-11-26T07:27:18.223 回答
1

尝试使用权重设置左右内容:

<TableRow>
       <TextView
           android:layout_width="0dp"
           android:layout_weight="1"
           android:layout_height="wrap_content"
           android:id="@+id/property_type_label"
           android:text="@string/property_type_label"/>
       <TextView
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:id="@+id/property_type"
           android:text="@string/property_type"/>
</TableRow>
于 2014-11-26T07:28:29.223 回答
1

使用 TextView 的重力而不是带有权重的 layout_gravity 来分配每个 TextView 的一半布局

 <TableRow>
   <TextView android:id="@+id/property_type_label"
    android:text="@string/property_type_label"
    android:padding="3dip"
    android:layout_weight="1"
    android:gravity="left" />

    <TextView android:id="@+id/property_type"
    android:text="@string/property_type"
    android:layout_weight="1"
    android:gravity="right"/>
</TableRow>
于 2014-11-26T07:34:07.683 回答