尽量用RelativeLayout不用 LinearLayoutRelativeLayout的alignWithParentIfMissing

针对RelativeLayout有一点需要注意,因为它内部是通过多 个View之间的关系而确定的框架,那么当其中某一个View因为某些需要调用 GONE  来完全隐藏掉后,会影响与其相关联的Views。Android为我们提供了一个属性  alignWithParentIfMissing    用于解决类似问题,当某一个View无法找到与其相关联 的Views后将依据 alignWithParentIfMissing  的设定判断是否与父级View对齐。
 
     参考代码:
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     android:layout_width="fill_parent"  
  3.     android:layout_height="?android:attr/listPreferredItemHeight"  
  4.   
  5.     android:padding="6dip">  
  6.   
  7.     <ImageView  
  8.         android:id="@+id/icon"  
  9.   
  10.         android:layout_width="wrap_content"  
  11.         android:layout_height="fill_parent"  
  12.   
  13.         android:layout_alignParentTop="true"  
  14.         android:layout_alignParentBottom="true"  
  15.         android:layout_marginRight="6dip"  
  16.   
  17.         android:src="@drawable/icon" />  
  18.   
  19.     <TextView    
  20.         android:id="@+id/secondLine"  
  21.   
  22.         android:layout_width="fill_parent"  
  23.         android:layout_height="26dip"   
  24.   
  25.         android:layout_toRightOf="@id/icon"  
  26.         android:layout_alignParentBottom="true"  
  27.         android:layout_alignParentRight="true"  
  28.   
  29.         android:singleLine="true"  
  30.         android:ellipsize="marquee"  
  31.         android:text="Simple application that shows how to use RelativeLayout" />  
  32.   
  33.     <TextView  
  34.         android:layout_width="fill_parent"  
  35.         android:layout_height="wrap_content"  
  36.   
  37.         android:layout_toRightOf="@id/icon"  
  38.         android:layout_alignParentRight="true"  
  39.         android:layout_alignParentTop="true"  
  40.         android:layout_above="@id/secondLine"  
  41.         android:layout_alignWithParentIfMissing="true"  
  42.   
  43.         android:gravity="center_vertical"  
  44.         android:text="My Application" />  
  45.   
  46. </RelativeLayout> 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值