Android的基本布局(第2课)

1、线性布局 LinearLayout

<LinearLayout 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:orientation="vertical"
    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" >
    <!-- android:orientation="vertical" 表示纵向分布 -->
    <!-- 1、线性布局 -->
    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="3"
        >
        <!-- android:weightSum 表示总共分多少份 -->
	    <Button
	        android:id="@+id/button1"
	        android:layout_width="0dp"
	        android:layout_height="wrap_content"
	        android:layout_weight="2"       
	        android:text="Button" />
	   <!-- android:layout_weight 表示所占的权重为多少 (weight权重优先于宽度,因此最好把width宽度设置为0dp)-->	
	    <Button
	        android:id="@+id/button2"
	        android:layout_width="0dp"
	        android:layout_height="wrap_content"
	        android:layout_weight="1"
	        android:text="Button" /> 
    </LinearLayout>

</LinearLayout>

2、相对布局 RelativeLayout

<?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:gravity="bottom">
    <!-- android:gravity="bottom" gravity设置重力在底部-->
	<!-- 2、相对布局 -->
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="Button" />
  <!-- 相对布局中嵌套线性布局 -->
  <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="3"
        android:layout_below="@+id/button1"
        >
        <!-- layout_below="@+id/button1" 表示在于 button1按钮的下面-->
	    <Button
	        android:id="@+id/button1"
	        android:layout_width="0dp"
	        android:layout_height="wrap_content"
	        android:layout_weight="2"       
	        android:text="Button" />

	    <Button
	        android:id="@+id/button2"
	        android:layout_width="0dp"
	        android:layout_height="wrap_content"
	        android:layout_weight="1"
	        android:text="Button" /> 
    </LinearLayout>
    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/button1"
        android:layout_alignLeft="@+id/button1"
        android:text="Button" />

</RelativeLayout>

3、帧布局 FrameLayout

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
	<!-- 3、帧布局,控制会叠加在一起(可以用来做刮刮乐) -->
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="第1帧" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="第2帧" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="第3帧" 
        android:visibility="gone"/>
    <!-- android:visibility="gone" 表示让该控制隐藏 -->

</FrameLayout>


猜你喜欢

转载自blog.csdn.net/qq15577969/article/details/80618394