Android 表行中的TextView内容被切断

Android 表行中的TextView内容被切断,android,android-layout,textview,android-tablelayout,Android,Android Layout,Textview,Android Tablelayout,首先,我做了一个谷歌搜索,查看了与TextView的文本被切断相关的StackOverFlow问题。他们没有帮助解决手头的问题,尽管他们对某些事情有了更好的理解 这是我的问题 我正在使用TableLayout显示带有两个文本字段的记录。每行有两个TextView单元格布局宽度设置为包裹内容。但是,即使文本以多行显示,该多行文本中的每一行都会在末尾被截断 e、 g 产生了这个观点 注意。需要再次访问。去看医生,直到医生站起来 测试的重要性。问题是,这很难 以获得访问的预约。尽管如此,我们仍需要

首先,我做了一个谷歌搜索,查看了与
TextView
的文本被切断相关的StackOverFlow问题。他们没有帮助解决手头的问题,尽管他们对某些事情有了更好的理解

这是我的问题

我正在使用
TableLayout
显示带有两个文本字段的记录。每行有两个
TextView
单元格<对于所有单元格,代码>布局宽度设置为
包裹内容
。但是,即使文本以多行显示,该多行文本中的每一行都会在末尾被截断

e、 g


产生了这个观点

注意。需要再次访问。去看医生,直到医生站起来 测试的重要性。问题是,这很难 以获得访问的预约。尽管如此,我们仍需要继续努力 直到他/她意识到这一点

以粗体书写的文本被截断

如果我使用
LinearLayout
代替
TableLayout
,它可以正常工作。但是,问题是我不能让每行的第二列从同一位置开始(没有硬编码)

请帮助我如何确保
TextView
内容不会被切断


这是上面给出的示例产生的视图。

尝试此代码并适合所有设备

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/bgcolor"
android:background="#ffffff"
android:orientation="horizontal"
android:padding="10dip" >

<LinearLayout
    android:id="@+id/llAvailableBookings"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center|top"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="25dip"
        android:gravity="center"
        android:textSize="24.5sp"
        android:visibility="gone" />

    <TableLayout
        android:id="@+id/tableLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:stretchColumns="*" >

        <TableRow>

            <TextView
                android:id="@+id/visitation_notes"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:text="Notes" />

            <TextView
                android:id="@+id/visitation_notes_value"
                android:layout_width="1dp"
                android:layout_height="wrap_content"
                android:singleLine="false"
                android:text="Need to visit again. Visit till the doctor understands the importance of the Test. The problem is, it is very difficult to get appointment for the visit. Still, we need to keep trying till the point reaches to him/her."
                android:textAlignment="viewStart" />
        </TableRow>
    </TableLayout>
</LinearLayout>

执行此操作

<TableRow>


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Note" />

    <TextView
        android:layout_weight="3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:text="Need to visit again. Visit till the doctor understands the importance of the Test. The problem is, it is very difficult to get appointment for the visit. Still, we need to keep trying till the point reaches to him/her." />


</TableRow>

我用以下代码解决了
表格行中被截断的
文本视图
元素问题:

<TableRow>

    <TextView
        android:layout_gravity="right"
        android:text="Address: "
        android:textStyle="bold"/>

    <TextView
        android:id="@+id/address"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:paddingRight="10dp"
        android:text="123 W. Abc St., San Diego CA 90333"/>

</TableRow>

TableRow是LinearLayout的子类/子类,因此这实际上是TableRow的默认行为与其超类不同的问题。如果水平对齐的LinearLayout包含多个文本视图,Lint将生成一个警告,以显式打开/关闭baselineAligned属性。但是TableRow具有相同的模糊性,没有方便的Lint警告

因此,您看到的布局错误是由于TableRow试图猜测基线对齐行为是什么而失败的。将
android:baselineAligned
属性添加到每个相关的TableRow中,您的布局将正确显示

<?xml version="1.0" encoding="utf-8"?>
   </TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content">
   <TableRow
        android:baselineAligned="false">
        <TextView
            android:text="Notes"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/visitation_notes" />
        <TextView
            android:text="Need to visit again. Visit till the doctor understands the importance of the Test. The problem is, it is very difficult to get appointment for the visit. Still, we need to keep trying till the point reaches to him/her."
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/visitation_notes_value"
            android:textAlignment="viewStart"/>
   </TableRow>
   </TableLayout>


Attach screenshot我现在已经附上了截图。现在请检查一下。这张桌子的宽度和高度是多少?我试过你的代码,它对我来说很好哦,我不确定我错过了什么。对于行,宽度设置为
match\u parent
,高度设置为
wrap\u content
。我不明白为什么这个问题被否决。我确实在同一主题上浏览了大量的问题,并发现代码片段作为答案,但没有足够的解释。因为这是我的第一个问题,如果我在提问之前能得到反馈,我将不胜感激。谢谢你的回答。但是,
singleLine
?此外,如果可以的话,我不想硬编码0dp和1dp的视图宽度。不管怎样,我尝试了上面的代码,但是视图看起来不太好。每行上几乎没有一个字。你用哪种设备进行模拟?我用的是Nexus4。这有什么不同吗?我更新了我的代码,请检查一下,并在所有设备上进行了测试。非常感谢advance@SatishThulva布局权重的主要用途是将部分拆分为多个部分,如果将表格行布局宽度设置为1,则子布局(Textview)会将权重1拆分为两个等效部分。这意味着,如果你给你的子版面宽度0dp,那么父版面权重1会自动将文本视图分割成相等的值(0.5权重和0.5权重),我想现在你可以投票给HsRaja答案了。谢谢你的帮助。它确实有效。但是,请帮助我为什么它有效。据我所知,
layout\u weight
属性帮助我们在确定每个
View
LinearLayout
中占用多少空间后,分配剩余的额外空间。当我们设置
layout\u width=wrap\u content
时,我不明白这是如何工作的,如果
TextView
,内容大小超过屏幕大小。您可以使用ems属性调整大小。如果你设置width=0dp,它仍然可以工作,但是你必须管理布局和权重值。你可以使用ems来固定textview的宽度。谢谢。最后,我为第一个视图设置了
layout\u width=0',为第二个视图设置了
TextView
s和
layout\u weight=1',为第二个视图设置了
layout\u weight=3
。但是,你能帮助我理解为什么我的原始代码不起作用吗?这是有效的,值得一提的是,布局权重与包装内容相结合是它起作用的原因。
<?xml version="1.0" encoding="utf-8"?>
   </TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content">
   <TableRow
        android:baselineAligned="false">
        <TextView
            android:text="Notes"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/visitation_notes" />
        <TextView
            android:text="Need to visit again. Visit till the doctor understands the importance of the Test. The problem is, it is very difficult to get appointment for the visit. Still, we need to keep trying till the point reaches to him/her."
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/visitation_notes_value"
            android:textAlignment="viewStart"/>
   </TableRow>
   </TableLayout>