Android TableRow 中的Textview显示不全

本文探讨了在Android TabLayout中遇到的文本溢出问题,特别是当TextView中的文本过长时无法完全显示的情况。文中详细介绍了如何使用`android:shrinkColumns`属性来解决这一问题,并提供了具体的XML布局代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近碰到了这个问题。

TabLayout 下面的 tabRow 中有2个TextView 如果输入的文本过长,会导致显示不全,这个问题真的困扰好几天了。

 

 

 

这个是 TableLayout 中没有设置 android:shrinkColumns 熟悉

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
        
         <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:shrinkColumns="1"
             >
             <TableRow
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content" >

                 <TextView
                     android:text="标题:" />

                 <TextView
                     android:text="@string/title1" />
             </TableRow>
             
              <TableRow
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content" >

                 <TextView
                     android:text="标题:" />

                 <TextView
                     android:text="@string/title2" />
             </TableRow>
             
               <TableRow
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content" >

                 <TextView
                     android:text="标题:" />

                 <TextView
                     android:text="@string/title3" />
             </TableRow>
             
                <TableRow android:background="@color/actionbar_title_color"
                >
                 <TextView
                     android:text="标题:" />

                 <TextView
                     android:text="@string/title4" />
             </TableRow>
        </TableLayout>

</LinearLayout>

 

 

 

android:shrinkColumns

The zero-based index of the columns to shrink. The column indices must be separated by a comma: 1, 2, 5. Illegal and duplicate indices are ignored. You can shrink all columns by using the value "*" instead. Note that a column can be marked stretchable and shrinkable at the same time.

Must be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character.

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol shrinkColumns.

Related Methods

我的理解:

android:shrinkColumns:以第0行为序,自动延伸指定的列填充可用部分:当LayoutRow里面的控件还没有布满布局时,shrinkColumns不起作用,设置了shrinkColumns=0,1,2,布局完全没有改变,因为LayoutRow里面还剩足够的空间。当LayoutRow布满控件时,设置了shrinkColumns=2,则控件自动向垂直方向填充空间

 

 

转载于:https://www.cnblogs.com/ifzy/archive/2013/03/27/2985412.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值