针对RelativLayout的alignWithParentIfMissing属性问题

本文详细介绍了在Android中使用RelativeLayout布局时遇到的问题及解决方案。特别是当一个视图因为其他视图隐藏而找不到相关视图时,alignWithParentIfMissing属性的作用变得尤为重要。

针对RelativeLayout布局,有一点问题,需要明确,因为它内部是多个view间的关系确定的框架,那么当其中的一个view因其它view隐藏后,会影响其相关的views,所以安卓提供一属性解决此问题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.         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>   


转载于:https://my.oschina.net/u/1792000/blog/363021

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值