android - TextView 无法正确分割线

标签 android scrollview textview android-tablelayout tablerow

我对某些“应该”有效但根本不起作用的问题有疑问。

TableRow 内的

TextView 未在应有的位置提供换行符,相反,此相同的 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 的右侧在屏幕外。

任何有关此问题的帮助将不胜感激。谢谢!

最佳答案

这应该适合您,使用权重总和和布局权重,并将表格宽度设置为与父级匹配,将 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

关于android - TextView 无法正确分割线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28180304/

相关文章:

Android Spanned、SpannedString、Spannable、SpannableString 和 CharSequence

android - 显示弹出窗口时将灰色应用于非 Activity 屏幕

android - 如何使用 Picasso 为 Google Marker 自定义图标创建语音气泡边框?

java - Android:由于 Web 服务 Http 请求, Activity 显示时间过长

android - ScrollView 不使用包含 Android 中动态内容的 LinearLayout 滚动

用于 UIScrollViews 内容的 iOS VIewController

android - 带有 DrawerLayout 的 ScrollView 中的 ListView

相当于 textCapSentences 的 android TextView

android - 检查以前消费的商品

java - 如何动态有效地应用 RTL