相对布局

来源:互联网 发布:友价房产源码 编辑:程序博客网 时间:2024/04/27 16:44
在相对布局中,个人觉得一个控件至少也要指定它的两处相对位置关系才可确定它的位置
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    tools:context=".MainActivity" ><!-- 一般需要指定至少两个相对位置才能确定一个控件的具体位置 -->    <!-- 添加一个居中显示的文本视图 -->    <TextView        android:id="@+id/textView1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/hello_world"         android:layout_centerInParent="true"        /><!--添加一个在button2左侧的按钮  --><Button     android:id="@+id/button1"    android:layout_toLeftOf="@+id/button2"    android:layout_below="@+id/textView1"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="左侧按钮"        /><Button    android:id="@+id/button2"    android:layout_below="@+id/textView1"    android:layout_alignRight="@+id/textView1"android:text="右侧按钮"android:layout_width="wrap_content"android:layout_height="wrap_content"/></RelativeLayout>

0 0