金馆长动态图表情包:相对布局详解
来源:百度文库 编辑:九乡新闻网 时间:2024/07/14 15:51:51
android:layout_above, android:layout_below, android:layout_toLeftOf, android:layout_toRightOf。于其他widget位置对齐,可以使用:android:layout_alignTop, android:layout_alignBottom, android:layout_alignLeft, android:layout_alignRigh, android:layout_alignBaseline, 最后一个通常用于label的对齐。语法格式例子:layout_toRightOf="@id/widget_a"
我们将创建下面的Activity,Android XML如下:
< RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5px"
>
android:layout_height="wrap_content"
android:text="URL:"
android:paddingTop="15px" />
android:layout_height="wrap_content"
android:layout_toRightOf="@id/label"
android:layout_alignBaseline="@id/label"
/>
textview是我们第一个基准widget,我们设置了android:paddingTop="15px",否则由于后面我们按此尽心个对齐,editiew会向上移并被chip最上端。由于editview上移,也导致了和下面button之间的间距过大。android是根据网格来安排widget的位置,每个widget都有一个确定的高度并匹配网格,如果widget被拉高,因为网格定位的缘故,button的相对位置并不会被抬高。同样的如果我们设置 android:paddingTop="30px",editview的位置下沉,同样由于网格的缘故,下面的button不会随着下沉,将和eidtiew的位置有所重叠,如图所示。
然则,我们怎么知道要给label设置15px,如果布局都需要根据这样的经验值,就相当郁闷,另一个解决方式,就是在定义edittext之前,就将label的对应位置根据其进行调整,然后再定义edittext。这在1.5版本之前有问题,我们需要设置AndroidManifest.xml,设定我们的最小运行版本环境为2.2,我们在manifest中设置:
android:layout_height="wrap_content"
android:text="URL:"
android:layout_alignBaseline="@+id/entry"
android:layout_alignParentLeft="true"
/>
android:layout_height="wrap_content"
android:layout_toRightOf="@id/label"
android:layout_alignParentTop="true"
/>