当前位置: 首页 > news >正文

Android 基础知识4-2.9 FrameLayout(帧布局)详解

一、FrameLayout(帧布局)概述

        FrameLayout又称作帧布局,它相比于LinearLayoutRelativeLayout要简单很多,因为它的应用场景也少了很多。这种布局没有方便的定位方式,所有的控件都会默认摆放在布局的左上角。

示例1代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical"><FrameLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:width="300px"android:height="300px"android:background="#aa0000" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:width="200px"android:height="200px"android:background="#00aa00" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:width="100px"android:height="100px"android:background="#0000aa" /></FrameLayout></LinearLayout>

效果图1:

 从布局中可以看出,红色、绿色、蓝色是依次蓝色在绿色上面,绿色在红色上面,因此可以得出FeameLayout中的控件都会默认摆放在布局的左上角。

        当然除了这种默认效果之外,我们还可以使用android:layout_gravity属性来指定控件在布局中的对齐方式,这和LinearLayout中的用法是相似的。

示例2:

<?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"><ImageViewandroid:id="@+id/iv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="right"android:src="@mipmap/ic_launcher" /><TextViewandroid:id="@+id/tv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="left"android:text="This is TextView" /></FrameLayout>

效果图2:

http://www.lryc.cn/news/13046.html

相关文章:

  • Go语言xorm框架
  • 19_微信小程序之优雅实现侧滑菜单
  • JSP中JDBC与javaBean学习笔记
  • 编译Android系统源码推荐的电脑配置
  • 加油站会员管理小程序实战开发教程10
  • shell编程之条件判断和流程控制
  • 第一次接触jquery
  • Vue中 引入使用 babel-polyfill 兼容低版本浏览器
  • ArcGIS Enterprise on Kubernetes 11.0安装示例
  • js 防抖函数 节流函数
  • Yarn节点unhealthy解决办法
  • 【jumpServer 功能梳理】
  • 中国各省人力资本测算就业人员受教育程度构成(2000-2021年)
  • java面试题-集合篇
  • Python 异步: 同时运行多个协程(10)
  • SVN 获取多版本间的更新内容
  • c++ const使用说明
  • VSTO 开发 EXCEL 委托与多线程的极简示例
  • spring之使用Spring的AOP
  • LeetCode LCP 66. 最小展台数量
  • 设计模式之模板方法模式
  • Python数据挖掘基础
  • Go基础-函数
  • AC的改进算法——TRPO、PPO
  • 【C++学习】list的使用及模拟实现
  • 动态规划专题精讲1
  • PPO(proximal policy optimization)算法
  • ElasticSearch基本使用
  • windows微软商店下载应用失败/下载故障的解决办法;如何在网页上下载微软商店的应用
  • MySQL进阶篇之InnoDB存储引擎