TextView 不能正确分割线
TextView doesn't split line correctly
我对 "should" 有效但根本无效的问题有疑问。
TextView
inside TableRow
没有提供换行符,而是这个 TextView
与 TableRow
的宽度相同,忽略那个 [=11] =] 已经在那里并占用了一些 space.
示例如下:
<?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
的右侧在屏幕外。
任何帮助都将不胜感激。谢谢!
使用\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上....但我没试过
\n
可以,但如果您动态需要它,那么您认为文本应该有特定的对齐方式(对齐)。如果没有第 3 方库,就无法证明 Android 上的文本。
您需要为 TableRow
添加一个内部容器。 TextViews
除非在您的布局中指定,否则不会相互交互。
您可以将 TextViews
添加到 RelativeLayout
并将组件布局 属性 添加到 "value" 字符串,使其始终位于 [=20] 的右侧=] 字符串.
android:layout_toRightOf="@+id/firstText"
这应该适合你,使用权重总和和布局权重并将 table 宽度设置为与父级匹配并将文本视图宽度设置为 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>
我对 "should" 有效但根本无效的问题有疑问。
TextView
inside TableRow
没有提供换行符,而是这个 TextView
与 TableRow
的宽度相同,忽略那个 [=11] =] 已经在那里并占用了一些 space.
示例如下:
<?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
的右侧在屏幕外。
任何帮助都将不胜感激。谢谢!
使用\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上....但我没试过
\n
可以,但如果您动态需要它,那么您认为文本应该有特定的对齐方式(对齐)。如果没有第 3 方库,就无法证明 Android 上的文本。
您需要为 TableRow
添加一个内部容器。 TextViews
除非在您的布局中指定,否则不会相互交互。
您可以将 TextViews
添加到 RelativeLayout
并将组件布局 属性 添加到 "value" 字符串,使其始终位于 [=20] 的右侧=] 字符串.
android:layout_toRightOf="@+id/firstText"
这应该适合你,使用权重总和和布局权重并将 table 宽度设置为与父级匹配并将文本视图宽度设置为 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>