TextView文本在TableLayout的列中切断

时间:2016-09-03 08:21:50

标签: android android-layout

TableLayout中有三列,第一列和第二列包含TextView,其中包含文字和其他属性,第三列包含TextView仅用于间距。

但是第一栏TextView的文字存在问题,显示在以下屏幕截图中。

Screenshot

此处的布局文件代码:

<com.github.aakira.expandablelayout.ExpandableRelativeLayout
    android:id="@+id/expandableLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/expandableButton1"
    android:background="@drawable/patient"
    android:padding="16dp"

    app:ael_duration="400"
    app:ael_expanded="true"
    app:ael_interpolator="bounce"
    app:ael_orientation="vertical">
    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        style="@style/scrollbar_shape_style"
        android:fillViewport="true"
        android:layout_height="340dp">
    <TableLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:shrinkColumns="*" android:stretchColumns="*" android:orientation="vertical" >
        <TableRow android:id="@+id/tableRow2" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" >
        <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Name:" android:textColor="#000000" android:layout_margin="1dp" android:gravity="start|center"/>
        <TextView android:layout_width="match_parent" android:id="@+id/pname" android:layout_height="wrap_content"  android:textColor="#606062" android:gravity="left" android:layout_margin="1dp" />
        <TextView />
    </TableRow>
        <TableRow android:id="@+id/tableRow3" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal">
        <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Gender:" android:textColor="#000000" android:layout_margin="1dp" android:gravity="start|center"/>
        <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/pgender"  android:textColor="#606062" android:gravity="left" android:layout_margin="1dp"/>
            <TextView />
        </TableRow>
        <TableRow  android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" >
        <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="DOB:" android:textColor="#000000" android:layout_margin="1dp" android:gravity="start|center"/>
        <TextView android:id="@+id/pdob" android:layout_width="match_parent" android:layout_height="wrap_content"  android:textColor="#606062" android:gravity="left" android:layout_margin="1dp"/>
        <TextView />
    </TableRow>

        <TableRow  android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" >
            <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="MRN:" android:textColor="#000000" android:layout_margin="1dp" android:gravity="start|center"/>
            <TextView android:id="@+id/pmrn" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="" android:textColor="#606062" android:gravity="left" android:layout_margin="1dp"/>
            <TextView />
        </TableRow>

        <TableRow  android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" >
            <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Active:" android:textColor="#000000" android:layout_margin="1dp" android:gravity="start|center"/>
            <TextView android:id="@+id/pactive" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="#606062" android:gravity="left" android:layout_margin="1dp"/>
            <TextView />
        </TableRow>
        <TableRow  android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" >
            <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Phone:" android:textColor="#000000" android:layout_margin="1dp" android:gravity="start|center"/>
            <TextView android:id="@+id/pphone" android:layout_width="match_parent" android:layout_height="wrap_content"  android:textColor="#606062" android:gravity="left" android:layout_margin="1dp"/>
            <TextView />
        </TableRow>
        <TableRow  android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" >
            <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Email:" android:textColor="#000000" android:layout_margin="1dp" android:gravity="start|center"/>
            <TextView android:id="@+id/pemail" android:layout_width="match_parent" android:layout_height="wrap_content"  android:textColor="#606062" android:gravity="left" android:layout_margin="1dp"/>
            <TextView />
        </TableRow>
        <TableRow  android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" >
            <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Disease:" android:textColor="#000000" android:layout_margin="1dp" android:gravity="start|center"/>
            <TextView android:id="@+id/pdisease" android:layout_width="match_parent" android:layout_height="wrap_content"  android:textColor="#606062" android:gravity="left" android:layout_margin="1dp"/>
            <TextView />
        </TableRow>
        <TableRow  android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" >
            <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Height:" android:textColor="#000000" android:layout_margin="1dp" android:gravity="start|center"/>
            <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/pheight" android:textColor="#606062" android:gravity="left" android:layout_margin="1dp"/>
            <TextView />
        </TableRow>
        <TableRow android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" >
            <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Address:" android:textColor="#000000" android:layout_margin="1dp" android:gravity="start|center"/>
            <TextView android:layout_width="match_parent" android:id="@+id/paddress" android:layout_height="wrap_content"  android:textColor="#606062" android:gravity="left" android:layout_margin="1dp"/>
            <TextView />
             </TableRow>
        <TableRow  android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" >
            <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Marital Status:" android:textColor="#000000" android:layout_margin="1dp" android:gravity="start|center"/>
            <TextView android:id="@+id/pmaritalstatus" android:layout_width="match_parent" android:layout_height="wrap_content"  android:textColor="#606062" android:gravity="left" android:layout_margin="1dp"/>
            <TextView />
        </TableRow>
        <TableRow  android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" >
            <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Multiple Birth:" android:textColor="#000000" android:layout_margin="1dp" android:gravity="start|center"/>
            <TextView android:id="@+id/pmultibirth" android:layout_width="match_parent" android:layout_height="wrap_content"  android:textColor="#606062" android:gravity="left" android:layout_margin="1dp"/>
            <TextView />
        </TableRow>


        <TableRow  android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" >
            <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Communication Language:" android:textColor="#000000" android:layout_margin="1dp" android:gravity="start|center"/>
            <TextView android:id="@+id/pcommlang" android:layout_width="match_parent" android:layout_height="wrap_content"  android:textColor="#606062" android:gravity="left" android:layout_margin="1dp"/>
            <TextView />
        </TableRow>
        <TableRow  android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" >
            <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Care Provider:" android:textColor="#000000" android:layout_margin="1dp" android:gravity="start|center"/>
            <TextView android:id="@+id/pcareprovider" android:layout_width="match_parent" android:layout_height="wrap_content"  android:textColor="#606062" android:gravity="left" android:layout_margin="1dp"/>
            <TextView />
        </TableRow>
        <TableRow  android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" >
            <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Race:" android:textColor="#000000" android:layout_margin="1dp" android:gravity="start|center"/>
            <TextView android:id="@+id/prace" android:layout_width="match_parent" android:layout_height="wrap_content"  android:textColor="#606062" android:gravity="left" android:layout_margin="1dp"/>
            <TextView />
        </TableRow>
        <TableRow  android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" >
            <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Ethnicity:" android:textColor="#000000" android:layout_margin="1dp" android:gravity="start|center"/>
            <TextView android:id="@+id/pethnicity" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="#606062" android:gravity="left" android:layout_margin="1dp"/>
            <TextView />
            </TableRow>
            <TableRow  android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" >
                <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Religion:" android:textColor="#000000" android:layout_margin="1dp" android:gravity="start|center"/>
                <TextView android:id="@+id/preligion" android:layout_width="match_parent" android:layout_height="wrap_content"  android:textColor="#606062" android:gravity="left" android:layout_margin="1dp"/>
                <TextView />
            </TableRow>

    </TableLayout>
    </android.support.v4.widget.NestedScrollView>

</com.github.aakira.expandablelayout.ExpandableRelativeLayout>

提前谢谢!

2 个答案:

答案 0 :(得分:2)

  

android:padding="16dp"删除root layout

<com.github.aakira.expandablelayout.ExpandableRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/expandableLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/expandableButton1"
    app:ael_duration="400"
    app:ael_expanded="true"
    app:ael_interpolator="bounce"
    app:ael_orientation="vertical">
  

并在Table Layout添加android:layout_marginLeft="15dp"

中进行更改
<TableLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      android:layout_marginLeft="15dp"
      android:shrinkColumns="*"
      android:stretchColumns="*">

答案 1 :(得分:0)

如果您尝试了所有方案,但仍未正确显示TextView,请在文本开头为String添加空格。

<string name="name">&#x20;Name</string> 

其中&#x20;是空格。

或者如果您从API获取字符串:

String name = " " + jsonName;