android studio帧布局实例
时间: 2023-06-05 10:48:06 浏览: 99
Android Studio中的帧布局是一种常用的布局方式,它可以让子视图在屏幕上重叠显示。下面是一个简单的帧布局实例:
```
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/background"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textSize="24sp"
android:textColor="@android:color/white"
android:layout_gravity="center"/>
</FrameLayout>
```
在这个例子中,我们使用了一个帧布局来显示一个背景图片和一个居中的文本视图。我们首先定义了一个帧布局,然后在其中添加了一个ImageView和一个TextView。ImageView用来显示背景图片,TextView用来显示文本。我们使用了layout_gravity属性来将TextView居中显示。由于帧布局的特性,TextView会覆盖在ImageView上面,从而实现了文本居中显示在背景图片上的效果。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)