Android中当一行显示两个TextView时,第一个可“…”,而第二个必须显示全部

在Android中当一行显示两个TextView时,第一个可“…”,而第二个必须全部显示这种布局时:

<RelativeLayout
    android:layout_width = "wrap_content"  --1:  fill_parent
    android:layout_height = "wrap_content"
    android:background="#cccccc"
    android:padding="20dip">

    <LinearLayout
        android:layout_width = "wrap_content"   --- 2:  fill_parent
        android:layout_height = "wrap_content"
        android:orientation = "horizontal" >
        <TextView
            android:id = "@+id/item_text_one"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:layout_weight = "1"
            android:ellipsize = "end"
            android:singleLine = "true"
            android:text = "text1的效果 效果 效果 效果 效果 效果 效果"  />

        <TextView
            android:id = "@+id/item_text_two"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:layout_marginLeft = "20dip"
            android:text = "text2的效果"  />

            --3:   android:gravity="right"   1,2,3位置修改,即可使text2不论text1文本内容多少都可以一直居右显示
    </LinearLayout>
</RelativeLayout>


运行结果为:

         

 

 

看上面代码可知,text1使用了weight属性,并置为1,text2没有使用,默认weight为0。

其实,layout_weight属性的意思就是说:android系统会按照两个TextView的warp_content来分配宽度,剩下的因为只有text1的weight = 1,所以剩下的空间都留给了text1,就能达成这种效果。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值