Android自适应布局

2018-12-11  本文已影响0人  淡蓝色梦想

顶部固定底部自适应

关键如下:

代码如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:clipChildren="false"
    android:clipToPadding="false"
    android:focusable="false"
    android:orientation="vertical"
    >
    <!-- 顶部固定:设置layout_height为wrap_content,使其根据内容设置高度 -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:focusable="false"
        android:background="@color/background_color"
        >
        ...
    </LinearLayout>

    <!-- 底部自适应:设置layout_height为match_parent,它将根据父容器进行自适应,即是抢占模式 -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:focusable="false"
        android:background="@color/background_color"
        >
        ...
    </LinearLayout>
</LinearLayout>

顶部固定底部自适应

关键如下:

代码如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:clipChildren="false"
    android:clipToPadding="false"
    android:focusable="false"
    android:orientation="horizontal"
    >
    <!-- 左侧固定:设置layout_width为wrap_content,使其根据内容设置宽度 -->
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:focusable="false"
        android:background="@color/background_color"
        >
        ...
    </LinearLayout>

    <!-- 右侧自适应:设置layout_width为match_parent,它将根据父容器进行自适应,即是抢占模式 -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:focusable="false"
        android:background="@color/background_color"
        >
        ...
    </LinearLayout>
</LinearLayout>
上一篇 下一篇

猜你喜欢

热点阅读