标签:
布局的背部除了放置控件外,也可以放置布局,通过多层布局的嵌套,可实现比较复杂的界面实现。android:orientation="vertical"
android:orientation="horizontal"
android:orientation="vertical"
android:orientation="horizontal"
android:layout_gravity
<EditText
android:id="@+id/input_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Type something"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Send"
android:layout_weight="1"
android:id="@+id/button1"
/>
<EditText
android:id="@+id/input_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:hint="Type something"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Send"
android:layout_weight="2"
android:id="@+id/button1"
/>
<EditText
android:id="@+id/input_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Type something"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send"
android:id="@+id/button1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1"
android:id="@+id/button1"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2"
android:id="@+id/button2"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 3"
android:id="@+id/button3"
android:layout_centerInParent="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 4"
android:id="@+id/button4"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 5"
android:id="@+id/button5"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"/>
android:layout_above="@id/button3"
android:layout_toRightOf="@id/button3"
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 3"
android:id="@+id/button3"
android:layout_centerInParent="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1"
android:id="@+id/button1"
android:layout_above="@id/button3"
android:layout_toLeftOf="@id/button3"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2"
android:id="@+id/button2"
android:layout_above="@id/button3"
android:layout_toRightOf="@id/button3"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 4"
android:id="@+id/button4"
android:layout_below="@id/button3"
android:layout_toLeftOf="@id/button3"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 5"
android:id="@+id/button5"
android:layout_below="@id/button3"
android:layout_toRightOf="@id/button3"/>
android:layout_alignRight
//一个控件的右边缘和另一个的右边缘对其
//同理还有
android:layout_alignLeft
android:layout_alignButtom
android:layout_alignTop
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:id="@+id/button"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/image_view"
android:src="@drawable/ic_launcher"/>
</FrameLayout>
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow>
//每一个TableRow代表一行,在每一行加入一个控件相当于加入了一列,因此其中的控件是不能指定宽度的
<TextView
android:layout_height="wrap_content"
android:text="Accout:" />
<EditText
android:id="@+id/account"
android:layout_height="wrap_content"
android:hint="Input your account"/>
</TableRow>
<TableRow>
<TextView
android:layout_height="wrap_content"
android:text="Password"/>
<EditText
android:id="@+id/password"
android:layout_height="wrap_content"
android:inputType="textPassword"/>
//textPassword使得EditText变为密码输入框
</TableRow>
<TableRow>
<Button
android:id="@+id/login"
android:layout_height="wrap_content"
android:layout_span="2"
//为了使表格变得好看,设置登陆按钮占据两列
android:text="Login"/>
</TableRow>
</TableLayout>
android:stretchColumns="1"
//表示如果表格不能完全占满屏幕宽度,就将第二列进行拉伸 0是拉伸第一列 以此类推
标签:
原文地址:http://blog.csdn.net/a360616218/article/details/50983975