-
2021-06-02 21:22:56
Android开发之FrameLayout布局
在Android开发中,FrameLayout是所有布局容器中最简单的一种,在前边博客中有介绍关于Android开发中线性布局LinearLayout的应用。LinearLayout采用的是线性平铺的布局模式,FrameLayout也被称为帧布局。
FrameLayout简单理解,可以将布局容器理解为一个单元素栈,先放入的视图在栈底,后放入的视图在栈顶,后放入的视图会覆盖先放入的视图。并且,FrameLayout不能够设置其内视图的位置,默认都是从左上角开始布局,这个布局模式在简单的重叠界面中使用十分方便。
使用代码进行FrameLayout布局示例如下:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FrameLayout frameLayout = new FrameLayout(this);
setContentView(frameLayout);
//添加子视图
TextView textView1 = new TextView(this);
textView1.setLayoutParams(new FrameLayout.LayoutParams(600,600));
textView1.setBackgroundColor(Color.RED);
frameLayout.addView(textView1);
TextView textView2 = new TextView(this);
textView2.setLayoutParams(new FrameLayout.LayoutParams(400,400));
textView2.setBackgroundColor(Color.YELLOW);
frameLayout.addView(textView2);
TextView textView3 = new TextView(this);
textView3.setLayoutParams(new FrameLayout.LayoutParams(200,200));
textView3.setBackgroundColor(Color.BLUE);
frameLayout.addView(textView3);
TextView textView4 = new TextView(this);
textView4.setLayoutParams(new FrameLayout.LayoutParams(100,100));
textView4.setBackgroundColor(Color.GREEN);
frameLayout.addView(textView4);
}
上面示例代码在FrameLayout中放入4个TextView,后放入的视图依次减小,运行后效果如下图所示:
FrameLayout应该是开发中很少使用到的一种布局模式,在十分简单的界面需求中,使用它往往十分方便。
专注技术,热爱生活,交流技术,也做朋友。
——珲少 QQ群:435043639
更多相关内容 -
Android自定义View设定到FrameLayout布局中实现多组件显示的方法 分享
2020-09-05 07:10:27Android自定义View设定到FrameLayout布局中实现多组件显示的方法 分享,需要的朋友可以参考一下 -
13、Android -- FrameLayout布局 基础学习
2022-07-06 22:17:27学习的属性较少 常用属性/设置 android:foreground:设置改帧布局容器的前景图像 android:foregroundGravity:设置前景图像显示的位置 名称解释 前景图像:永远处于帧布局最上面,直接面对用户的图像,就是不会被覆盖的...由于FameLayout比较简单,所有元素都是默认左上角开始,叠加显示。学习的属性较少
常用属性/设置
- android:foreground:设置改帧布局容器的前景图像
- android:foregroundGravity:设置前景图像显示的位置
名称解释
前景图像:永远处于帧布局最上面,直接面对用户的图像,就是不会被覆盖的图片。
(个人理解:有些类似div中z-index 最大值,或者算是图像前置)
示例
1、res/layout/activity_frame_layout.xml
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="match_parent" android:layout_width="match_parent" > <FrameLayout android:id="@+id/fl_one" android:background="@color/red" android:layout_width="300dp" android:layout_height="300dp" /> <FrameLayout android:id="@+id/fl_two" android:background="@color/yellow" android:layout_width="200dp" android:layout_height="200dp" android:foreground="@drawable/ic_baseline_lock_24" android:foregroundGravity="center|bottom" /> <FrameLayout android:id="@+id/fl_three" android:background="@color/green" android:layout_width="100dp" android:layout_height="100dp" /> </FrameLayout>
效果图
-
Android FrameLayout布局
2020-05-05 20:46:23FrameLayout 又称单帧布局,是 Android 所提供的布局方式里最简单的布局方式,它指定屏幕上的一块空白区域,在该区域填充一个单一对象。例如图片、文字、按钮等。应用程序开发人员不能为 FrameLayout 中填充的组件...FrameLayout
FrameLayout 又称单帧布局,是 Android 所提供的布局方式里最简单的布局方式,它指定屏幕上的一块空白区域,在该区域填充一个单一对象。例如图片、文字、按钮等。
应用程序开发人员不能为 FrameLayout 中填充的组件指定具体填充位置,默认情况下,这些组件都将被固定在屏幕的左上角,后放入的组件会放在前一个组件上进行覆盖填充,形成部分遮挡或全部遮挡。
开发人员可以通过组件的 android:layout_gravity 属性对组件位置进行适当的修改。
实例 FrameLayoutDemo 演示了 FrameLayout 的布局效果。该布局中共有 4 个 TextView 组件,前 3 个组件以默认方式放置到布局中,第 4 个组件修改 gravity 属性后放置到布局中,运行效果如图 所示。实例 FrameLayoutDemo 中的布局文件 main.xml 的代码如下:
<?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"
android:orientation="vertical">
<!--顶部的轮播-->
<com.youth.banner.Banner
android:id="@+id/banner_home_header"
android:layout_width="match_parent"
android:layout_height="240dp"/>
<!--轮播下的布局-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!--功能区-->
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@drawable/bg_layout_border">
</RadioGroup>
<!--入住 离店日期选择-->
<LinearLayout
android:id="@+id/ll_home_date_select"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_layout_border"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<TextView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<TextView
android:id="@+id/tv_home_total_night"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="共n晚" />
<TextView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<TextView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</LinearLayout>其中:
android:layout_width="wrap_content"
android:layout_height="wrap_content"表明 FrameLayout 布局覆盖了整个屏幕空间。
实例 FrameLayoutDemo 中的 strings.xml 文件内容如下:<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<string name="app_name">FrameLayoutDemo</string>
<string name="first">第一层</string>
<string name="second">第二层</string>
<string name="third">第三层</string>
<string name="forth">第四层</string>
</resources>从运行后的结果可见,前 3 个被放置到 FrameLayout 的 TextView 组件都是以屏幕左上角为基点进行叠加的。第4个 TextView 因为设置了 android:layout_gravity="bottom" 属性而显示到了布局的下方。可自行将 android:layout_gravity 属性值修改为其他属性,查看运行效果。
-
FrameLayout布局
2021-06-11 14:33:15从左上角开始绘制 常用属性 android:foreground 设置前景 android:foregroundGravity 设置前景...FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" and从左上角开始绘制
常用属性
android:foreground 设置前景
android:foregroundGravity 设置前景位置activity_main.xml
<?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"> <FrameLayout android:background="#ff0000" android:foreground="@drawable/tp" android:foregroundGravity="right|bottom" android:layout_width="400dp" android:layout_height="400dp"/> <FrameLayout android:background="#00ffff" android:foreground="@drawable/tp2" android:foregroundGravity="right|bottom" android:layout_width="200dp" android:layout_height="200dp"/> <FrameLayout android:background="#ff00ff" android:layout_width="100dp" android:layout_height="100dp"/> </FrameLayout>
-
Android手机应用界面开发 帧布局(FrameLayout) Android中使用FrameLayout布局基本属性时的常见问题.pptx
2020-10-14 20:29:15Android中使用FrameLayout布局基本属性时的常见问题北京信息职业技术学院 | 范美英Android中使用FrameLayout布局的常见问题 | 问题描述问题描述1android中的FrameLayout可以根据屏幕的百分比布局吗?Android中使用... -
Android的FrameLayout布局介绍
2018-08-04 11:43:35FrameLayout布局的属性有android:foreground和android:foregroundGravity。 android:foreground属性:属性值为图片资源,用于设置前景图片,意思是此图片是位于所有组件之上,不管添加顺序。 android:... -
Android中使用FrameLayout布局完成教学案例的要求说明.pdf
2022-07-10 04:29:30Android中使用FrameLayout布局完成教学案例的要求说明.pdf 学习资料 复习资料 教学资源 -
Android中使用FrameLayout布局完成教学案例的代码清单.pdf
2022-07-10 04:28:22Android中使用FrameLayout布局完成教学案例的代码清单.pdf 学习资料 复习资料 教学资源 -
FrameLayout布局 Kotlin.Android
2020-12-14 15:40:04FrameLayout布局 <?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=... -
FrameLayout布局------层次控制显示
2021-06-02 17:21:39多层次代码控制分别显示: android:layout_width="fill_parent" android:layout_height="fill_parent"> android:id="@+id/start_view"-----------------------在代码中使用id和...需要两个fragment布局,一个主布局m -
FrameLayout布局完成霓虹灯效果
2014-08-19 11:14:26我是刚刚学习的新手,刚学习完成了用FrameLayout布局完成霓虹灯效果的小程序,与大家分享一下。 -
Android FrameLayout布局中的控件设置居中动态设置
2018-11-27 10:06:47Android FrameLayout 布局文件静态设置里面的控件时是默认左上角叠加的。 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent&... -
关于FrameLayout布局的位置问题
2016-04-14 20:32:42关于FrameLayout布局的位置问题 1.首先来看看android:layout_gravity和android:gravity的使用区别。 android:gravity: 这个是针对控件里的元素来说的,用来控制元素在该控件里的显示位置。例如,在一个Button... -
LinearLayout RelativeLayout FrameLayout布局常用属性
2022-02-17 14:21:24部分内容是截取享学课堂老师的ppt 视频在小破站可以看 感谢leo老师 LinearLayout中 layout_weight 权重的分配是依据 orientation参数赋予的值来决定分配width或者...RelativeLayout布局 FrameLayout常见属性 ... -
Android布局之帧布局FrameLayout详解
2021-01-20 10:43:26在这个布局中,所有的子元素都不能被指定放置的位置,他们统统防御这块区域的左上角, 并且后面的子元素直接覆盖在前面的子元素之上,将前面的子元素部分和全部遮挡。 用途 常用于进度条的表示 <?xml version... -
android的FrameLayout布局的常规用途?
2021-05-26 10:45:21相对布局、帧布局、线性布局、表格布局、和 网格布局,其他四种都好理解,就是不太理解FrameLayout,作者在介绍FrameLayout时用了一个动画实例 -- 例子加上名字让我第一反应就是这个FrameLayout布局就是专门来做一些... -
六大布局之FrameLayout的使用
2020-12-14 03:31:19上一期我们给大家讲解了LinearLayout,这一期我们为大家讲解一下FrameLayout(帧布局)的使用,相较于其他布局,FrameLayout可以说的上是最简单的一个,并且其使用范围相对来说也相对较小,但是也是Android中的六大... -
Android FrameLayout帧布局
2022-02-17 15:44:48FrameLayout帧布局是可以覆盖的 布局之间可以覆盖的 <FrameLayout android:layout_marginTop="12dp" android:layout_marginStart="12dp" android:layout_width="120dp" android:layout_height="160dp" > ... -
Framelayout布局中嵌套多个布局layout的显示
2015-01-13 15:06:33我开始的做法是直接调用myview1.setVisibility(View.GONE)这种办法使其隐藏或者显示,但是我发现始终是无效的,可能如一个网友说的framelayout的特性就是分层叠加,后面的布局会逐层叠加上去,即使View.GONE了但是... -
FrameLayout布局(1)
2015-11-30 14:58:351、能够实现控件覆盖 ...///使用定时器来发送信息更改动态frame = (FrameLayout) findViewById(R.id.myframe); // 定义一个定时器对象,定时发送信息给handler new Timer().schedule(new TimerTask() { @Override -
Framelayout 布局
2015-12-16 09:24:46在FrameLayout布局里,定义任何空间的位置相关的属性都毫无意义。控件自动的堆放在左上角,根本不听你的控制。 有些情况下,我们可能必须要用到Framelayout。 这时候我们只需要记住一个标准:后面的代码总是会... -
FrameLayout布局的增强版—CoordinatorLayout
2016-07-19 15:47:02CoordinatorLayout默认情况下可理解成一个FrameLayout,它的布局方式默认是一层一层叠上去。 本文主要讲的是CoordinatorLayout+AppBarLayout的组合使用,绿色的部分代表导航栏。 效果图如下: 2.使用方法 在... -
【Android frameLayout布局】使用framelayout布局将图片和文字叠加到一起形成一张图片
2020-07-04 17:35:45Framelayout又称作帧布局,主要用于进行层次结构的布局,这种布局没有方便的定位方式。想把两个组件叠加到一起形成一张图像的效果就可以用FrameLayout。 如:在图片中添加文字 <FrameLayout android:... -
Android中FrameLayout布局的相关知识点
2020-12-14 15:36:07FrameLayout也是较常用的布局,其下级视图无法指定所处的位置,只能统统从上级FrameLayout的左上角开始添加,并且后面添加的子视图会把之前的子视图覆盖掉。框架布局一般用于需要重叠显示的场合,比如绘图,游戏界面...