FrameLayout

该布局管理器为x轴正向,y轴负向分布 按布局先后顺序,后者覆盖前者。
FrameLayout内有一个特殊的标签
android:foreground=""
该标签可以设置前景图像,且该图像不会被内部布局覆盖
另外可以通过foregroundGravity标签修改前景图像的位置
android:foregroundGravity="left|top"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foreground="@drawable/icon_collectioned_2x"
android:foregroundGravity="left|top"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="aaaaaaaaaaaaaaaaaaaaaaa"
android:background="#FFF000"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="aaaaaaaaaaaaaaaaa"
android:background="#FF0000"
/>
</FrameLayout>

这篇博客介绍了FrameLayout在Android开发中的使用,它按照x轴正向,y轴负向的顺序布局,后面的视图会覆盖前面的视图。特别地,通过设置android:foreground属性可以添加不会被内部视图覆盖的前景图像,并利用android:foregroundGravity调整其位置。示例代码展示了如何在FrameLayout中添加TextView并设置前景图像和位置。

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



