·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> app软件开发 >> Android开发 >> Android布局之FrameLayout帧布局

Android布局之FrameLayout帧布局

作者:佚名      Android开发编辑:admin      更新时间:2022-07-23

前言

作为android六大布局中最为简单的布局之一,该布局直接在屏幕上开辟出了一块空白区域,

当我们往里面添加组件的时候,所有的组件都会放置于这块区域的左上角;

帧布局的大小由子控件中最大的子控件决定,如果都组件都一样大的话,同一时刻就只能能看到最上面的那个组件了!

当然我们也可以为组件添加layout_gravity属性,从而制定组件的对其方式

帧布局在游戏开发方面用的比较多,等下后面会给大家演示一下比较有意思的两个实例

(-)帧布局简介

帧布局容器为每个加入的其中的组件创建一个空白的区域称为一帧每个子组件占据一帧,这些帧都会根据gravity的属性执行自动对齐

(二)常用属性:

android:foreground:设置该帧布局容器的前景图像

android:foregroundGravity:设置前景图像显示的位置

(三)使用

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent">
 <FrameLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  >
  <TextView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_gravity="center"
   android:width="300dp"
   android:height="300dp"
   android:background="#f00"/>
  <TextView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_gravity="center"
   android:width="200dp"
   android:height="200dp"
   android:background="#0f0"/>
  <TextView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_gravity="center"
   android:width="100dp"
   android:height="100dp"
   android:background="#00f"/>
 </FrameLayout>
</LinearLayout>

以上内容给大家介绍了Android布局之FrameLayout帧布局,希望大家喜欢。