-
2018-08-04 11:43:35
FrameLayout主要用于需要重叠的组件视图。如实现时钟等,秒针覆盖时针和分针。
FrameLayout布局的属性有android:foreground和android:foregroundGravity。
android:foreground属性:属性值为图片资源,用于设置前景图片,意思是此图片是位于所有组件之上,不管添加顺序。
android:foregroundGravity属性:用于设置前景图片在布局中的位置,属性值与android:gravity一样。如果不设置此属性,则前景图片不管有多小都默认充满整个布局,如果设置了,就在相应位置以图片实际大小显示。
其实RelativeLayout也可以替换一些FrameLayout,但是每个布局都有自己的作用,这样开发效率才高。
更多相关内容 -
LinearLayout RelativeLayout FrameLayout布局常用属性
2022-02-17 14:21:24部分内容是截取享学课堂老师的ppt 视频在小破站可以看 感谢leo老师 LinearLayout中 layout_weight 权重的分配是依据 orientation参数赋予的值来决定分配width或者height的权重,分割线...FrameLayout常见属性 ...部分内容是截取享学课堂老师的ppt 视频在小破站可以看 感谢leo老师
LinearLayout中 layout_weight 权重的分配是依据 orientation参数赋予的值来决定分配width或者height的权重,分割线新建view来实现也行
RelativeLayout布局
FrameLayout常见属性
-
Android手机应用界面开发 帧布局(FrameLayout) Android中使用FrameLayout布局基本属性时的常见问题.pptx
2020-10-14 20:29:15Android中使用FrameLayout布局基本属性时的常见问题北京信息职业技术学院 | 范美英Android中使用FrameLayout布局的常见问题 | 问题描述问题描述1android中的FrameLayout可以根据屏幕的百分比布局吗?Android中使用... -
Android布局中FrameLayout和fragment中的使用。
2021-06-04 02:12:39需要纠正第1个错误,在FrameLayout视图的子组件中,layout_weight属性是无效的,你会得到如下的黄色感叹号警告: Invalid layout param in a FrameLayout: layout_weight 按你贴出来的布局文件,right_fragment ...我在看《第一行代码》中的碎片部分,对其中的这部分代码没有办法理解
<?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="horizontal">
<fragment
android:id="@+id/left_fragment"
android:name="com.example.qiao.fragmenttest.LeftFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2" />
<FrameLayout
android:id="@+id/right_layout"
android:layout_width="10dp"
android:layout_weight="1"
android:layout_height="match_parent">
<fragment
android:id="@+id/right_fragment"
android:name="com.example.qiao.fragmenttest.RightFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
</FrameLayout><!--相对布局-->
</LinearLayout>
我的主要困惑是不理解这里为什么要添加
FrameLayout
,作用是覆盖在
fragment
上,类似于浮动的效果吗?
同时
<FrameLayout
android:id="@+id/right_layout"
android:layout_width="10dp"
android:layout_weight="1"
android:layout_height="match_parent">
这部分属性到底作用在哪里又该怎么理解,如何确定他们的大小。
FrameLayout 的作用
在 Activity 中托管一个 UI Fragment 有两种方式:(1)添加 fragment 到 activity 布局中;(2)在 activity 代码中添加 fragment。
left_fragment
和
right_fragment
都是采用了第1种方式。
对于第2种方式,需要在布局文件中为 Fragment 添加一个容器,以安排 Fragment 在 activity 视图中的位置。实践中常选用
FrameLayout
作为容器。
至于你贴出来的
right_layout
的作用,要看代码的意图。我猜作者是想演示如何通过代码添加一个Fragment(也就是第2种方式),用来与第1种方式作对比。也可能没有任何用意,因为布局文件是错误的!
需要纠正第1个错误,在FrameLayout视图的子组件中,layout_weight属性是无效的,你会得到如下的黄色感叹号警告:
Invalid layout param in a FrameLayout: layout_weight
按你贴出来的布局文件,right_fragment 由于layout_width 为0dp,根本就不会显示。
需要纠正第2个错误, 是注释的错误,FrameLayout 并不是相对布局,它就是一个容器,向其中添加的任何子组件,需要通过
layout_gravity
属性值决定在父视图中的位置,而各个子组件并不能像 RelativeLayout 一样,定义相对位置。
android:layout_weight 属性的工作原理
该属性告知 LinearLayout 如何安排子组件的布局。对于水平方向的 LinearLayout,查看
layou_width
和
layout_weight
以决定子组件的宽度。
你贴出来的布局中,LinearLayout 有2个子组件,下文称 left_fragment 为 child1,称 right_layout 为 child2:
第1步,查看 layout_width 属性值,为 child1 分配0dp,为 child2 分配10dp;
第2步,依据 layout_weight 属性值分配剩余的宽度,child1 将分配到 2/3, child2 将分配到 1/3.
你看到最外面LinearLayout的orientation了没,然后FrameLayout的宽只有10dp。 😀
-
帧布局(FrameLayout)及属性
2021-06-17 13:20:08帧布局FrameLayout直接继承ViewGroup组件,帧布局容器每加入一个组件创建一个空白区域,每个组件占据一帧,添加的组件是一个一个叠在一起的。android:layout_width="fill_parent"android:layout_height="fill_parent...帧布局FrameLayout直接继承ViewGroup组件,帧布局容器每加入一个组件创建一个空白区域,每个组件占据一帧,添加的组件是一个一个叠在一起的。
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#f00"
android:text="1"
android:height="320dp"
android:width="320dp" />
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#0f0"
android:height="280dp"
android:width="280dp"
android:text="2"/>
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#00f"
android:height="240dp"
android:width="240dp"
android:text="3"/>
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#ff0"
android:height="200dp"
android:width="200dp"
android:text="4"/>
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#f0f"
android:height="160dp"
android:width="160dp"
android:text="5"/>
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#0ff"
android:height="120dp"
android:width="120dp"
android:text="6" />
-
Android入门--UI开发--5种常见布局简介(FrameLayout,TableLayout,AbsouluteLayout)
2022-03-14 19:24:26Android入门--UI开发--5种常见布局简介(FrameLayout,TableLayout,AbsouluteLayout) -
常见界面布局之FrameLayout(帧布局)
2020-07-04 10:05:221.什么是FrameLayout(帧布局) FrameLayout (帧布局)用于在屏幕上创建一块空白区域,添加到该区域中的每个子控件占一帧,这些帧会一个一个叠加在一起,后加入的控件会叠加在上一个控件上层。默认情况下,帧布局中... -
13、Android -- FrameLayout布局 基础学习
2022-07-06 22:17:27学习的属性较少 常用属性/设置 android:foreground:设置改帧布局容器的前景图像 android:foregroundGravity:设置前景图像显示的位置 名称解释 前景图像:永远处于帧布局最上面,直接面对用户的图像,就是不会被覆盖的... -
Android FrameLayout布局
2020-05-05 20:46:23FrameLayout 又称单帧布局,是 Android 所提供的布局方式里最简单的布局方式,它指定屏幕上的一块空白区域,在该区域填充一个单一对象。例如图片、文字、按钮等。应用程序开发人员不能为 FrameLayout 中填充的组件... -
Android布局之FrameLayout帧布局
2021-01-05 22:18:16前言 作为android六大布局中最为简单的布局之一,该布局直接在屏幕上...帧布局容器为每个加入的其中的组件创建一个空白的区域称为一帧每个子组件占据一帧,这些帧都会根据gravity的属性执行自动对齐 (二)常用属性: -
FrameLayout布局
2021-06-11 14:33:15常用属性 android:foreground 设置前景 android:foregroundGravity 设置前景位置 activity_main.xml <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android=... -
Android中帧布局FrameLayout的常用属性.pdf
2022-07-10 06:35:20Android中帧布局FrameLayout的常用属性.pdf 学习资料 复习资料 教学资源 -
Android中FrameLayout布局的相关知识点
2020-12-14 15:36:07FrameLayout也是较常用的布局,其下级视图无法指定所处的位置,只能统统从上级FrameLayout的左上角开始添加,并且后面添加的子视图会把之前的子视图覆盖掉。框架布局一般用于需要重叠显示的场合,比如绘图,游戏界面... -
FrameLayout布局------层次控制显示
2021-06-02 17:21:39多层次代码控制分别显示:android:layout_width="fill_parent...android:id="@+id/start_view"-----------------------在代码中使用id和setVisibility的属性来设置需要的层显示android:layout_width="fill_par... -
Android五大布局详解——FrameLayout(帧布局)
2021-06-03 12:00:49FrameLayout这个布局相对前面两节介绍的布局就简单了很多,因此它的应用场景也就特别的少。这种布局没有方便的定位方式,所有的控件都会默认摆放在布局的左上角。新建UILayoutTestThree工程,修改activity_main.xml... -
关于FrameLayout布局的位置问题
2016-04-14 20:32:42关于FrameLayout布局的位置问题 1.首先来看看android:layout_gravity和android:gravity的使用区别。 android:gravity: 这个是针对控件里的元素来说的,用来控制元素在该控件里的显示位置。例如,在一个Button... -
FrameLayout帧布局
2021-07-09 05:27:59FrameLayout(帧布局)可以说是六大布局中最为简单的一个布局,这个布局直接在屏幕上开辟出一块空白的区域,当我们往里面添加控件的时候,会默认把它们放到这块区域的左上角,而这种布局方式却没有任何的定位方式... -
FrameLayout层叠布局
2020-05-28 15:35:11在开发安卓项目中,FrameLayout层叠布局是六大布局中最为简单的一个布局!使用FrameLayout层叠布局却没有任何的定位方式,所以它应用的场景并不多。 一、FrameLayout概念: FrameLayout层叠布局(帧布局)是最简单的... -
基本布局之 - FrameLayout
2018-05-11 14:53:061.2 使用layout_gravity属性来指定控件在布局中的对齐方式 基本布局之 - FrameLayout FrameLayout又称作帧布局,这种布局没有方便的定位方式,所有控件都会默认放在布局左上角 1.1 默认效果 最终视图 ... -
【转载】Android布局讲解之FrameLayout布局
2017-06-08 15:41:52在FrameLayout布局里,定义任何空间的位置相关的属性都毫无意义。控件自动的堆放在左上角,根本不听你的控制。 看以下的例子: [html] view plain copy ... -
Android应用开发之FrameLayout(帧布局)
2022-03-29 17:27:34帧布局介绍 -
【Android 布局】FrameLayout(帧布局)
2021-06-04 16:43:20文章目录FrameLayout(帧布局)本节引言1.常用属性2.实例演示1)最简单的例子2)随手指移动的图片3)跑动的萌妹子 FrameLayout(帧布局) 本节引言 FrameLayout(帧布局)可以说是六大布局中最为简单的一个布局,这个布局直接... -
Android FrameLayout ( 帧布局 )
2021-06-02 21:41:36Android FrameLayout (帧布局) 直接在屏幕上开辟出一块空白的区域,当我们往里面添加控件的时候,会默认把它们放到这块区域的左上角FrameLayoutFrameLayout (帧布局) 有点类似于把零散的大小不一的纸按左上角对齐的... -
FrameLayout 帧布局
2022-03-06 16:14:50帧布局 -
FrameLayout(帧布局的两种实现效果)
2019-11-18 11:58:58FrameLayout(帧布局)可以说是六大布局中最为简单的一个布局,这个布局直接在屏幕上开辟出一块空白的区域,当我们往里面添加控件的时候,会默认把他们放到这块区域的左上角,而这种布局方式却没有任何的定位方式,所以它... -
Framelayout 布局
2015-12-16 09:24:46在FrameLayout布局里,定义任何空间的位置相关的属性都毫无意义。控件自动的堆放在左上角,根本不听你的控制。 有些情况下,我们可能必须要用到Framelayout。 这时候我们只需要记住一个标准:后面的代码总是会... -
android - Android:如何将FrameLayout中的线性布局与底部对齐? - 堆栈内存溢出
2021-05-26 17:46:42使用属性layout_gravity对齐FrameLayout中的任何视图android:layout_gravity:"bottom"/>但是,如果您尝试将其放置在其他布局的底部。 然后使用相对布局。例xmlns:android=...