欢迎来到代码驿站!

Android代码

当前位置:首页 > 移动开发 > Android代码

Android布局之FrameLayout帧布局

时间:2021-03-20 09:59:48|栏目:Android代码|点击:

前言

作为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帧布局,希望大家喜欢。

上一篇:Android自定义view实现标签栏功能(只支持固定两个标签)

栏    目:Android代码

下一篇:Android AndBase框架使用封装好的函数完成Http请求(三)

本文标题:Android布局之FrameLayout帧布局

本文地址:http://www.codeinn.net/misctech/84116.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有