Android API Guides---Relative Layout

Relative Layout

RelativeLayout的是显示的相对位置子视图视图组。每个视图的位置可以被指定为相对于兄弟元素(如到左或低于另一个视图)或相对于母体RelativeLayout的区域中的位置(如对准底部,左侧或中心)。

Android API Guides---Relative Layout_第1张图片

一个RelativeLayout的是设计的用户界面,因为它可以消除嵌套视图组,并保持你的布局层次扁平,从而提高性能非常强大的工具。如果你发现自己使用多个嵌套的LinearLayout组,您可以用一个RelativeLayout的来替换它们。
定位视图
RelativeLayout的让子视图相对它们的位置指定父视图或对方(由ID指定)。所以,你可以通过调整右边界两个元素,或者做一个低于另外,在屏幕居中,左为中心,等等。默认情况下,所有子视图在布局的左上角绘制的,所以你必须定义使用可从RelativeLayout.LayoutParams的各种布局属性每个视图的位置。
一些可用的意见在RelativeLayout的诸多布局属性包括:

android:layout_alignParentTop

如果“真”,使得该视图的顶部边缘相匹配的父的顶部边缘

android:layout_centerVertical

如果“真”,中心这个孩子垂直其父项内。

android:layout_below

位置与资源ID指定的视图低于该视图的顶部边缘

android:layout_toRightOf

职位这一观点与资源ID指定的视图右侧的左边缘。
这些只是几个例子。所有的布局属性在RelativeLayout.LayoutParams记录。
每个布局属性的值是一个布尔值,以使相对于父RelativeLayout的或引用反对该视图应定位布局另一种观点认为ID的布局位置。
在你的XML布局,对布局其他意见的依赖可以按任意顺序进行声明。例如,您可以声明“厂景”被定位低于“视图2”,即使“意见”是在层次结构中声明的最后一个视图。下面的例子演示了这样的情景。

每个控制每个视图的相对位置的属性的被强调。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="16dp"
    android:paddingRight="16dp" >
    <EditText
        android:id="@+id/name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/reminder" />
    <Spinner
        android:id="@+id/dates"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_below="@id/name"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@+id/times" />
    <Spinner
        android:id="@id/times"
        android:layout_width="96dp"
        android:layout_height="wrap_content"
        android:layout_below="@id/name"
        android:layout_alignParentRight="true" />
    <Button
        android:layout_width="96dp"
        android:layout_height="wrap_content"
        android:layout_below="@id/times"
        android:layout_alignParentRight="true"
        android:text="@string/done" />
</RelativeLayout>
Android API Guides---Relative Layout_第2张图片


你可能感兴趣的:(java,android,api,sdk,阅读)