学习Layout总结
一、RelativeLayout(相对布局)
相对布局有两种,一种是相对容器而言,另一种是相对控件而言。
*下面是对控件的一种
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
app:srcCompat="@drawable/smile1"
android:id="@+id/imageView"
android:layout_centerInParent="true"/>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
app:srcCompat="@drawable/rabbit4"
android:layout_below="@+id/imageView"
android:layout_alignLeft="@+id/imageView2"
android:layout_alignStart="@+id/imageView2"
android:layout_marginTop="24dp"
android:id="@+id/imageView3" />
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
app:srcCompat="@drawable/rabbit2"
android:layout_alignTop="@+id/imageView4"
android:layout_toRightOf="@+id/imageView"
android:layout_toEndOf="@+id/imageView"
android:layout_marginLeft="33dp"
android:layout_marginStart="33dp"
android:id="@+id/imageView5" />
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
app:srcCompat="@drawable/rabbit1"
android:id="@+id/imageView4"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/imageView"
android:layout_toStartOf="@+id/imageView"
android:layout_marginRight="41dp"
android:layout_marginEnd="41dp" />
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
app:srcCompat="@drawable/rabbit3"
android:id="@+id/imageView2"
android:layout_marginBottom="25dp"
android:layout_above="@+id/imageView"
android:layout_alignLeft="@+id/imageView"
android:layout_alignStart="@+id/imageView"
android:layout_marginLeft="13dp"
android:layout_marginStart="13dp" />
二、LinearLayout(线性布局)
*在UI开发中,线性布局默认为水平显示,如果想要设置垂直,用属性orientation;
*weight表示权重
*控件布局中对齐方式用layout_gravity,文字在布局中对齐方式用gravity
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:layout_weight="1"
android:layout_marginTop="10dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ababab"
android:layout_weight="1"
android:layout_marginTop="10dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0000ff"
android:layout_weight="1"
android:layout_marginTop="10dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00ff00"
android:layout_weight="1"
android:layout_marginTop="10dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff0000"
android:layout_weight="1"
android:layout_marginTop="10dp"/>
三、TableLayout(表格布局)
*每一行用TableRow
<TableRow
>
<EditText android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Account:"/>
<TextView android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="Input your account"
android:gravity=""
android:layout_weight="1"/>
</TableRow>
<TableRow
>
<EditText android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password:"/>
<TextView android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/>
</TableRow>
<TableRow>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"
android:layout_weight="1"
android:id="@+id/button" />
</TableRow>
四、GridLayout(网格布局)
五、FrameLayout(帧布局)
*帧布局在局面上是一帧一帧显示的;
*帧布局在子控件默认是左上角对齐;
<Button
android:text="Button1"
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/button" />
<Button
android:text="Button2"
android:layout_width="80dp"
android:layout_height="80dp"
android:id="@+id/button2" />
六、AbsoluteLayout(相对布局)
*可以确定准确的坐标值,代码是:
android:laoyout_x 确定水平的位置;
android:laoyout_y 确定竖直的位置;
以上就是我对六个布局的了解,希望以后更深入了解。