TextView没有正确分割线

时间:2015-01-27 21:25:29

标签: android scrollview textview android-tablelayout tablerow

我遇到的问题是"应该"工作,但它根本没有。

TextView内{p} TableRow不提供换行符,而是TextViewTableRow的宽度相同,忽略那一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的右侧在屏幕外。

任何帮助都会受到赞赏。谢谢!

4 个答案:

答案 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>

split text image

答案 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)

\n可以正常工作,但如果您需要动态,那么您认为文本应该具有特定的对齐方式(对齐)。没有第三方库,没有办法证明Android上的文本是正确的。

我前段时间找到了一些Github库,herehere