针对RelativeLayout有一点需要注意,因为它内部是通过多个View之间的关系而确定的框架,那么当其中某一个View因为某些需要调用GONE
来完全隐藏掉后,会影响与其相关联的Views。Android为我们提供了一个属性 alignWithParentIfMissing
用于解决类似问题,当某一个View无法找到与其相关联
的Views后将依据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圆角图片背景,自定义属性 背景 圆角半径
Android 开发入门 对 RelativeLayout的基本属性的讲解和用法 ,更容易的帮你理解和使用
Android布局入门,LinearLayout和RelativeLayout的理解和应用
Android 相对布局 RelativeLayout 属性
Android RelativeLayout 的翻译应用。希望能给大家帮助
android布局属性RelativeLayout详解.
总结android中相对布局RelativeLayout的所有属性及使用方法。适合初级程序员
介绍一下RelativeLayout的一些属性,针对于刚学习android开发的朋友
LinearLayout与RelativeLayout混合用
RelativeLayout 上 下 中 左 右布局 demo
介绍了android 中 RelativeLayout 下的各种属性。linux下打开.
Android相对布局RelativeLayout的基本用法,相对布局是最实用的布局。
android实现自定义RelativeLayout可拖动、缩放、旋转TextView
相对布局我最新喜欢的布局,也是game开发,照相机以及增钱现实中最常用的布局!
安卓动态控制RelativeLayout的组件
RelativeLayout点击效果,背景色的变化,通过两种方法:1. 直接用图片资源; 2. 用color资源
DragView 可拖拽的view,继承自RelativeLayout
【Android开发学习25】界面布局之相对布局RelativeLayout(代码)
像 RelativeLayout 一样的 RadioGroup
一个Android XML布局的例子,主要利用xml文件进行布局,里边用到的是RelativeLayout。具体的本例中: 非洲草原地图:用到了FrameLayout的使用;ActivityMain演示了linerLayout。 个性化表单ActivityLayout 演示...