帧布局
<?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:foreground="@mipmap/ic_launcher"
android:foregroundGravity="center"
>
<TextView
android:layout_width="400dp"
android:layout_height="400dp"
android:background="#ff0000"
android:layout_gravity="center"
/>
<!--android:layout_gravity="center_horizontal|center_vertical"另一种写法
-->
<TextView
android:layout_width="350dp"
android:layout_height="350dp"
android:layout_gravity="center"
android:background="#00ff00"/>
<TextView
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_gravity="center"
android:background="#00ffff"/>
<TextView
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_gravity="center"
android:background="#ff00ff"/>
<TextView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:background="#ffff00"
android:text="最后一个黄色的文本"
android:gravity="right"/>
</FrameLayout>
本文展示了一个使用帧布局(FrameLayout)实现的视图层级叠加效果的示例。通过不同大小的TextView并设置不同的背景颜色,实现了从大到小依次嵌套的效果。此示例有助于理解帧布局中视图的绘制顺序及层级关系。
8373

被折叠的 条评论
为什么被折叠?



