我遇到的问题是"应该"工作,但它根本没有。
TextView
内{p} TableRow
不提供换行符,而是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
的右侧在屏幕外。
任何帮助都会受到赞赏。谢谢!
答案 0 :(得分:1)
您需要向TableRow
添加内部容器。除非在布局中指定,否则TextViews
不会互相交互。
您可以将TextViews
添加到RelativeLayout
,并将组件布局属性添加到&#34;值&#34;字符串始终位于&#34;键的右侧&#34;字符串。
android:layout_toRightOf="@+id/firstText"
答案 1 :(得分:1)
这应该适合您,使用权重和布局权重并将表格宽度设置为匹配父级和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>
答案 2 :(得分:0)
使用\n
强制换行
android:text="test test test test\ntest test test test test test test\ntest test test test test test\ntest test test test test"
现在还没有测试过,但它应该可以正常工作
...如果你想动态尝试:
android:scrollHorizontally="false"
在textview上的....但我还没试过呢
答案 3 :(得分:0)