解决RelativeLayout中gone后布局错位问题:RelativeLayout的alignWithParentIfMissing。
2014-12-12 19:30
633 查看
针对RelativeLayout有一点需要注意,因为它内部是通过多个View之间的关系而确定的框架,那么当其中某一个View因为某些需要调用GONE 来完全隐藏掉后,会影响与其相关联的Views。Android为我们提供了一个属性
layout_alignWithParentIfMissing 用于解决类似问题,当某一个View无法找到与其相关联 的Views后将依据layout_alignWithParentIfMissing 的设定判断是否与父级View对齐。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="6dip"
android:src="@drawable/icon" />
<TextView
android:id="@+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_toRightOf="@id/icon"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:singleLine="true"
android:ellipsize="marquee"
android:text="Simple application that shows how to use RelativeLayout" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/icon"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_above="@id/secondLine"
android:layout_alignWithParentIfMissing="true"
android:gravity="center_vertical"
android:text="My Application" />
</RelativeLayout>
layout_alignWithParentIfMissing 用于解决类似问题,当某一个View无法找到与其相关联 的Views后将依据layout_alignWithParentIfMissing 的设定判断是否与父级View对齐。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="6dip"
android:src="@drawable/icon" />
<TextView
android:id="@+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_toRightOf="@id/icon"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:singleLine="true"
android:ellipsize="marquee"
android:text="Simple application that shows how to use RelativeLayout" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/icon"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_above="@id/secondLine"
android:layout_alignWithParentIfMissing="true"
android:gravity="center_vertical"
android:text="My Application" />
</RelativeLayout>
相关文章推荐
- 解决RelativeLayout中 gone之后的布局错位问题。RelativeLayout的alignWithParentIfMissing
- 解决RelativeLayout中 gone之后的布局错位问题。RelativeLayout的alignWithParentIfMissing
- 解决RelativeLayout中 gone之后的布局错位问题。RelativeLayout的alignWithParentIfMissing[转载]
- 尽量用RelativeLayout不用 LinearLayoutRelativeLayout的alignWithParentIfMissing
- 【Android】解决Listview侧滑与上下滑动问题+侧滑通用布局 DragRelativeLayout
- [问题记录]AutoLayout下UIScrollView 布局错位及解决方法
- 有关RelativeLayout布局中, 当一个控件被左右两个控件夹在中间时, 此控件如何靠近两个控件中的一个的问题?
- android开发中遇到的问题解决之RelativeLayout执行measure(w,h)方法时,出现NullPointerException的异常情况
- 关于android R.layout 中找不到已存在的布局文件问题的解决
- 关于android R.layout 中找不到已存在的布局文件问题的解决
- 关于android R.layout 中找不到已存在的布局文件问题的解决
- glm编译错误问题解决 formal parameter with __declspec(align('16')) won't be aligned
- android 使用RelativeLayout布局出现的问题汇总(不定期添加更新)
- listView 中relativeLayout 布局的 android:layout_alignParentBottom="true" 无效的解决办法
- listview的item为RelativeLayout时android:layout_alignParentBottom无效的解决方法
- 开发问题及解决--java.lang.IllegalStateException: Circular dependencies cannot exist in RelativeLayout
- 解决问题“Error inflating class android.widget.RelativeLayout”
- [原]问题解决办法:there are offline or missing virtual drivers with preserved cache
- RelativeLayout.LayoutParams 使用addRule失效的问题解决办法
- 关于android R.layout 中找不到已存在的布局文件问题的解决