固定布局 - Android

本篇文章记录的是android应用中的固定布局(FrameLayout).固定布局,相对于屏幕的左上角. (FrameLayout)

常见属性

属性说明
foreground设置前景
foregroundGravity设置前景位置

代码示例

<?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"
    android:background="@color/pink"
    android:orientation="vertical">


    <ImageView
        android:layout_width="match_parent"
        android:layout_height="150dp"
        
        android:contentDescription="描述"
        android:scaleType="centerCrop"
        android:src="@drawable/images" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:gravity="center"
        android:orientation="vertical"

        >

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="send"
            android:text="显示模态对话框" />


    </LinearLayout>
</FrameLayout>

上面代码执行之后,会得到诸如下面的执行结果:

image-20230831052342651.png