使用框架布局管理器居中显示层叠的正方形

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ancientear/article/details/82532676

框架布局管理器用< FrameLayout>表示,在该布局管理器中,每加入一个组件,都将建立一个空白的区域,通常称为一帧,这些帧都会根据gravity属性执行自动对齐。默认情况下,框架布局是从屏幕的左上角(0,0)坐标点开始布局,多个组件层叠排序,后面的组件覆盖前面的组件。
所以说框架布局管理器也被称为帧布局管理器。

实现过程:在xml文件中,添加一个< FrameLayout>框架布局管理器,在该布局管理器中,添加3个剧种显示的< TextView>,并且分别为它们指定不同的颜色和大小,用于更好地体现层叠效果。

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
    tools:context="com.example.shenfan.absolutelayout.MainActivity">

    <TextView
        android:layout_width="280dp"
        android:layout_height="280dp"
        android:background="#004433"
        android:layout_gravity="center"/>

    <TextView
        android:layout_width="240dp"
        android:layout_height="240dp"
        android:background="#00aa00"
        android:layout_gravity="center"/>

    <TextView
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:background="#00dd00"
        android:layout_gravity="center"/>


</FrameLayout>

运行效果如下图:
这里写图片描述

猜你喜欢

转载自blog.csdn.net/ancientear/article/details/82532676