关于布局中控件的优先加载(Weight)问题

  • 注意:此属性是作用在线性布局下的
  • 一行中有两个布局,前面的是一个TextView,后面是ImageView一个小图标,由于前面的TextView要显示的文本内容的长短是不固定的,如果过长就会把后面的ImageView给覆盖住,我们就看不到ImageView,如下图:
    这里写图片描述

  • 解决方案:我们可以在前面的TextView上加上android:layout_weight=”1”属性,这样就会先把后面的控件加载完再加载TextView,这样就可以显示,如下图:
    这里写图片描述

布局代码如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:tools="http://schemas.android.com/tools"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       tools:context="com.example.dialog.MainActivity" >

       <TextView
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_weight="1"
           android:singleLine="true"
           android: ="end"
           android:text="11232313213123123132132123132123123132132132132132132" />

       <ImageView 
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:src="@drawable/abc_btn_check_to_on_mtrl_015"
           />

    </LinearLayout>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值