您的位置:首页 > 产品设计 > UI/UE

Android UI(Layouts)-FrameLayout 详解

2016-06-04 11:43 363 查看
1.FrameLayout 是什么 ?(what)

1)View

2)ViewGroup

3)帧布局
2.FrameLayout 应用场合?

按层次布局时可以使用FrameLayout
3.FrameLayout 具体应用

1)布局方式(按层布局,一层一层的放,从左上角开始)

2)常用属性

a)layout_gravity

FrameLayout是五大布局中最简单的一个布局,在这个布局中,整个界面被当成一块空白备用区域,所有的子元素都不能被指定放置的位置,它们统统放于这块区域的左上角,并且后面的子元素直接覆盖在前面的子元素之上,将前面的子元素部分和全部遮挡。

显示效果如下:(四层都叠加到了一起)



设置layout_gravity属性,来改变它们的位置。("right|top")【右上角】("right|bottom")【右下角】值可以用|来组合,同理左下角为("left|bottom")

这里就不多说了,自己可以去练习尝试。显示效果如下:



代码如下:

<span style="font-family: Arial, Helvetica, sans-serif;"><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"</span>
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第一层"
android:textSize="24sp" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="第二层"
android:textSize="24sp" />

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="第三层"
android:textSize="24sp" />

<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:text="第四层"
android:textSize="24sp" />

</FrameLayout>

注意:子控件的宽和高都为"wrap_content"。如果宽和高都为"match_parent"的话,

设置该属性android:layout_gravity是没有效果的,设置android:gravity该属性

也可以伪实现错开位置。文本框本身还是左上角堆叠在一起的,只不过是内容错开而已。android:gravity是控制控件内部文本的位置。所以一般不会用到这个属性。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: