问题描述
我想要的是当文本很长时,表格形状不应扭曲。如我添加的图片所示,第一个文本很长,其他单元格和文本已损坏。我想解决这个问题。
<TableLayout
android:id="@+id/table"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="30dp"
android:layout_marginHorizontal="10dp"
android:background="#f1f1f1"
>
<TableRow>
<horizontalscrollview
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:maxLines="1"
android:text="fospfdmglfdmglğpkdsağgorjgdfglkdfdsfsdfsdfg"
android:layout_weight="1"
android:gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email"
android:textStyle="bold"
android:layout_weight="1"
android:gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tel"
android:textStyle="bold"
android:layout_weight="1"
android:gravity="center"/>
</LinearLayout>
</horizontalscrollview>
</TableRow>
<TableRow>
解决方法
请检查此代码,我更改了 layout_width 并且工作正常。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TableLayout
android:id="@+id/table"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="30dp"
android:layout_marginHorizontal="10dp"
android:background="#f1f1f1">
<TableRow>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:layout_weight=".5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:gravity="center"
android:text="fospfdmglfssssssssssssssssdfglkdfdsfsdfsdfg"
/>
<TextView
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Email"
android:textStyle="bold"
android:gravity="center"/>
<TextView
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Tel"
android:textStyle="bold"
android:gravity="center"/>
</LinearLayout>
</TableRow>
</TableLayout>
</LinearLayout>