解决RelativeLayout中gone后布局错位问题:RelativeLayout的alignWithParentIfMissing。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值