首页 > 其他分享 >Android 基础知识4-2.9 FrameLayout(帧布局)详解

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

时间:2023-02-25 12:32:55浏览次数:34  
标签:layout height content width 2.9 FrameLayout wrap Android android


一、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">

<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="300px"
android:height="300px"
android:background="#aa0000" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="200px"
android:height="200px"
android:background="#00aa00" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:width="100px"
android:height="100px"
android:background="#0000aa" />
</FrameLayout>

</LinearLayout>


效果图1:

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

 从布局中可以看出,红色、绿色、蓝色是依次蓝色在绿色上面,绿色在红色上面,因此可以得出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">

<ImageView
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:src="@mipmap/ic_launcher" />

<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="This is TextView" />

</FrameLayout>


效果图2:

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

标签:layout,height,content,width,2.9,FrameLayout,wrap,Android,android
From: https://blog.51cto.com/u_15360378/6085287

相关文章

  • Android 基础知识4-3.1 TextView(文本框)详解
    一、前言    TextView就是一个显示文本标签的控件,就是用来显示文本。可以在代码或者XML中设置字体,字体大小,字体颜色,字体样式(加粗级斜体),文字截断(比如:只显示10个字,......
  • 上班第一天 Android 环境配置
    其实是昨天把大概回归Android开发第一天学会查然后等待反正我是不希望以后再查了写出来吧去谷歌那边把androidstudio下载下来更新jdk版本(与传统的java开发不同......
  • Android笔记--FileProvider
    FileProvider介绍继承于ContentProvider,本质上依旧是用于跨境通信,对第三方应用暴露文件,并授予文件读写地权限具体内容1、在Strings.xml里面配置一个常量2、在Manifest......
  • Android笔记--通过MediaStore查询图片
    相关描述已经完成发送彩信功能之后,就来继续向前走一步,来到MediaStore查询图片界面啦!具体步骤实现1、简简单单地一个界面<?xmlversion="1.0"encoding="utf-8"?><Line......
  • Android Studio 设置文本内容
    首先在Androidstudio中设置文本内容有两种方式1、在XML文件中通过属性android:text设置文本2、在java代码中调用文本视图的对象的setText方法设置文本具体如下1、......
  • Android 观察App运行日志和面对安装工程中需要在
    Android采用Log工具打印日志,它将各类日志划分为五个等级;log.e表示错误信息,比如可能导致程序崩溃的异常log.w表示警告信息log.i表示一般消息log.d表示调试信息。可把程......
  • Android-简单增删改查-初步实现主要页面
    我先想做出个简单增删改查连上数据库,能把学生姓名列出来,可以添加学生数据今天时间很紧,搁宿舍敲了半天把页面写出来了,剩下的代码还不少,一口气也做不完,我也有点熬不住了。......
  • android stdio中textview控件的属性
    android:id//可以通过此id找到该控件android:layout_width//宽度android:layout_height//高度android:layout_background//设置背景的颜色、图片或是其他文件复制预期图片......
  • Android 应用接入 Firebase Crashlytics 进行崩溃分析上报
    前言所在公司的项目中有一款应用应客户要求,需要接入FirebaseCrashlytics,在此提前练手,也做个总结。本文以最新的Gradle7.5为例,如果Gradle版本比较低,添加依赖那一章......
  • Android Studio-Button的学习
    今天学习了Button,也学习了Button事件,但是事件学的不好,明天会重复对Button的学习1:<Buttonandroid:text="按钮"android:background="@drawable/btn_sele......