RelativeLayout中的子view的layout_height="match_parent"不管用

今天在写listview中的item时,发现RelativeLayout中的子view的layout_height="match_parent"不管用。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="@color/wheat" >
    <TextView 
        android:id="@+id/title_drag_list_item"
        android:layout_alignParentLeft="true"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_centerVertical="true"
        android:gravity="center_vertical"
        android:textSize="30sp"
        />
</RelativeLayout>
4.0.3的系统,搞不懂为啥

---------------------------------------------------

后来发现,其实不是RelativeLayout中的子view的layout_height="match_parent"不管用,而是relativeLayout的layout_height没起作用。

listview的item的高度是适应于item内部的容纳view的最大高度的,也就是说,他自己是无法设置高度的,这个类似于marginTop(或者bottom)不起作用。

而子view的match_parent又是适应于parent的最大高度,因此子view的高度成为了item内所有子view的最大高度,最终成为了大家都是wrap_parent。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/wheat" >
    
    <TextView 
        android:id="@+id/title_drag_list_item"
        android:layout_alignParentLeft="true"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_centerVertical="true"
        android:gravity="center_vertical"
        android:textSize="30sp"
        />
    
    <ImageView
        android:id="@+id/sort_touch_area"
        android:layout_alignParentRight="true"
        android:layout_width="100dp"
        android:layout_height="40dp"
        android:layout_centerVertical="true"
        android:background="@color/skyblue"
        android:src="@drawable/liwei_icon_list_item_sort"
        android:scaleType="centerInside"
        android:contentDescription="for sort area"
        />

</RelativeLayout>

比如上面,Textview的高度最终也是40dp了。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值