布局(LinearLayout,RelativeLayout,FrameLayout,TableLayout,GridLayout,ConstraintLayout)

时间:2021-06-30 18:44:14   收藏:0   阅读:0

LinearLayout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:gravity="center_horizontal|bottom"
    android:divider="@drawable/ic_baseline_horizontal_rule_24"
    android:showDividers="middle"
    android:dividerPadding="20dp"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <View android:layout_height="1dp"
        android:layout_width="match_parent"
        android:background="#ff0000"/>

    <LinearLayout android:layout_height="100dp"
        android:layout_gravity="left"
        android:layout_width="100dp"
        android:background="#ff0000"/>

    <LinearLayout android:layout_height="100dp"
        android:layout_width="100dp"
        android:background="#00ff00"/>

    <LinearLayout android:layout_height="100dp"
        android:layout_width="100dp"
        android:background="#0000ff"/>

</LinearLayout>

RelativeLayout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:padding="10dp"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <RelativeLayout
        android:id="@+id/lt1"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_centerInParent="true"
        android:background="#ff0000"/>

    <RelativeLayout
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_above="@id/lt1"
        android:layout_margin="100dp"
        android:background="#00ff00"/>

</RelativeLayout>

FrameLayout

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:layout_height="match_parent"
    android:layout_width="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <FrameLayout android:layout_height="300dp"
        android:layout_width="300dp"
        android:background="#ff0000"/>

    <FrameLayout android:layout_height="200dp"
        android:layout_width="200dp"
        android:foreground="@drawable/ic_baseline_language_24"
        android:foregroundGravity="right|bottom"
        android:background="#0000ff"/>

    <FrameLayout android:layout_height="100dp"
        android:layout_width="100dp"
        android:background="#00ff00"/>


</FrameLayout>

TableLayout

android:collapseColumns="1,3"
android:stretchColumns="2"
<?xml version="1.0" encoding="utf-8"?>
<TableLayout android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:shrinkColumns="2"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <TableRow>
        <Button android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_span="2"
            android:text="按钮0"/>

        <Button android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_column="3"
            android:text="按钮1"/>
    </TableRow>

    <TableRow>
        <Button android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="按钮0"/>

        <Button android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="按钮1"/>

        <Button android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="按钮2"/>

        <Button android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="按钮3"/>

        <Button android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="按钮4"/>
    </TableRow>

    <Button android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="按钮0"/>

    <Button android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="按钮1"/>

</TableLayout>

GridLayout

<?xml version="1.0" encoding="utf-8"?>
<GridLayout android:layout_height="match_parent"
    android:layout_width="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <Button android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="按钮0"/>

    <Button android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_row="1"
        android:layout_column="0"
        android:layout_columnSpan="3"
        android:layout_gravity="fill"
        android:text="按钮1"/>

    <Button android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_row="0"
        android:layout_column="1"
        android:text="按钮2"/>

    <Button android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_columnWeight="1"
        android:layout_rowWeight="1"
        android:text="按钮3"/>

    <Button android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="按钮4"/>
</GridLayout>

ConstraintLayout

评论(0)
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!