您的位置:首页 > 移动开发 > Android开发

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

2016-09-07 12:56 711 查看
在Android中当一行显示两个TextView时,第一个可“…”,而第二个必须全部显示这种布局时:

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

<LinearLayout
android:layout_width = "wrap_content"
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的效果"  />
</LinearLayout>
</RelativeLayout>


运行结果为:


          



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

其实,layout_weight属性的意思就是说:android系统会按照两个TextView的warp_content来分配宽度,剩下的因为只有text1的weight = 1,所以剩下的空间都留给了text1,就能达成这种效果。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐