我对某些“应该”有效但根本不起作用的问题有疑问。
TableRow
内的 TextView
未在应有的位置提供换行符,相反,此相同的 TextView
与 TableRow< 的宽度相同
,忽略一个 TextView
已经存在并占用一些空间。
这里是示例:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical"
android:weightSum="1" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="0.4"
android:scrollbars="vertical" >
<TableLayout
android:id="@+id/tableAtTest"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="@+id/firstContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="2dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:gravity="center_vertical"
android:text="first description"
android:textColor="#000000"
android:textSize="@dimen/smallSize"
android:textStyle="bold" />
<TextView
android:id="@+id/firstText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:text="test test test test test test test test test test test test test test test test test test test test test test "
android:textColor="#000000"
android:textSize="@dimen/smallSize" />
</TableRow>
<TableRow
android:id="@+id/secondContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="2dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:gravity="center_vertical"
android:text="second description"
android:textColor="#000000"
android:textSize="@dimen/smallSize"
android:textStyle="bold" />
<TextView
android:id="@+id/secondText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:text="test2 test2 test2 test2 test2 test2 test2 test2 test2 test2 test2 test2 test2 test2 test2 test2 test2 test2 test2 "
android:textColor="#000000"
android:textSize="@dimen/smallSize" />
</TableRow>
</TableLayout>
</ScrollView>
<android.support.v4.view.ViewPager
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pagerOnTest"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="0.6"
tools:context=".TestActivity" >
</android.support.v4.view.ViewPager>
</LinearLayout>
</RelativeLayout>
如果您查看字段 @id/firstText
和 @id/secondText
所占用的宽度,您会看到 TextView
的右侧在屏幕外。
任何有关此问题的帮助将不胜感激。谢谢!
最佳答案
这应该适合您,使用权重总和和布局权重,并将表格宽度设置为与父级匹配,将 TextView 宽度设置为 0dp,这样它将动态渲染:
<TableLayout
android:id="@+id/tableAtTest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="2">
<TableRow
android:id="@+id/firstContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="2dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:gravity="center_vertical"
android:text="first description"
android:textColor="#000000"
android:textStyle="bold"
android:layout_weight="1"/>
<TextView
android:id="@+id/firstText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:text="test test test test test test test test test test test test test test test test test test test test test test "
android:textColor="#000000"
android:layout_weight="1" />
</TableRow>
</TableLayout>
关于android - TextView 无法正确分割线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28180304/