Android: FrameLayout帧布局

  • 两分钟掌握FrameLayout帧布局

https://baijiahao.baidu.com/s?id=1575325525978446&wfr=spider&for=pc

一、认识FrameLayout

帧布局是Android布局中最简单的一种,使用FrameLayout标签。

帧布局为每个加入其中的控件创建一个空白区域(称为一帧,每个控件占据一 帧)。釆用帧布局方式设计界面时,只能在屏幕左上角显示一个控件,如果添加多个控件,这些控件会按照顺序在屏幕的左上角重叠显示。

下表显示了 FrameLayout常用的XML属性及相关方法说明。

----------------------------------------------------------------------------------------------

https://www.cnblogs.com/skywang12345/p/3154093.html

1 FrameLayout简介

对于FrameLayout,官方介绍是:
FrameLayout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view, because it can be difficult to organize child views in a way that's scalable to different screen sizes without the children overlapping each other. You can, however, add multiple children to a FrameLayout and control their position within the FrameLayout by assigning gravity to each child, using the android:layout_gravity attribute.

即,设计FrameLayout是为了显示单一项widget。通常,不建议使用FrameLayout显示多项内容;因为它们的布局很难调节。不用layout_gravity属性的话,多项内容会重叠;使用layout_gravity的话,能设置不同的位置。

注意: 区分“android:gravity”和“android:layout_gravity”。
android:gravity            :是对控件本身来说的,是用来设置“控件自身的内容”应该显示在“控件自身体积”的什么位置,默认值是左侧。
android:layout_gravity:是相对于控件的父元素来说的,设置该控件在它的父元素的什么位置。

----------------------------------------------------------------------------------------------

  • 2.2.4 FrameLayout(帧布局)

http://www.runoob.com/w3cnote/android-tutorial-framelayout.html

FrameLayout(帧布局)可以说是六大布局中最为简单的一个布局,这个布局直接在屏幕上开辟出一块空白的区域,当我们往里面添加控件的时候,会默认把他们放到这块区域的左上角,而这种布局方式却没有任何的定位方式,所以它应用的场景并不多;

帧布局的大小由控件中最大的子控件决定,如果控件的大小一样大的话,那么同一时刻就只能看到最上面的那个组件!后续添加的控件会覆盖前一个!

虽然默认会将控件放置在左上角,但是我们也可以通过layout_gravity属性,指定到其他的位置!

猜你喜欢

转载自blog.csdn.net/dc3120/article/details/87903258