Android03--Android之UI布局01FrameLayout

来源:互联网 发布:淘宝运营团队分工 编辑:程序博客网 时间:2024/06/09 20:37

学习安卓的第三天,今天来学习一下FrameLayout
我们使用布局方式时:如果能使用第三方的布局就是用第三方的布局;

1.认识FrameLayout(5.0之前)

在5.0之前,放置在FrameLayout中 控件,所有放在布局里的控件,都按照层次堆叠在屏幕的左上角。后加进来的控件覆盖前面的控件。

       <TextView        android:id="@+id/textview1"        android:layout_width="300dp"        android:layout_height="300dp"        android:layout_gravity="center"        android:background="#33ffff" />    <TextView        android:id="@+id/textview2"        android:layout_width="240dp"        android:layout_height="240dp"        android:layout_gravity="center"        android:background="#FF33ccff" />    <TextView        android:id="@+id/textview3"        android:layout_width="180dp"        android:layout_height="180dp"        android:layout_gravity="center"        android:background="#FF3399ff" />    <TextView        android:id="@+id/textview4"        android:layout_width="120dp"        android:layout_height="120dp"        android:layout_gravity="center"        android:background="#FF3366ff" />    <TextView        android:id="@+id/textview5"        android:layout_width="60dp"        android:layout_height="60dp"        android:layout_gravity="center"        android:background="#FF3300ff" />

这里写图片描述
默认会将控件放置在左上角,但是我们也可以通过layout_gravity属性和gravity属性指定到其他位置; (注意textView的宽高是否wrap-content)
常用属性:(但这个并不打破FrameLayout的布局特性,如果有多个水下TextView,他还是会叠加放置的.)

 <TextView        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:textColor="#f00"        android:textSize="30dp"        android:layout_gravity="center"        android:text="Hello World!" />

这里写图片描述

 <TextView        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:textColor="#f00"        android:textSize="30dp"        android:gravity="center"        android:text="Hello World!" />

这里写图片描述

常用的两个属性:

android:foreground:设置该帧布局容器的前景图像android:foregroundGravity:设置前景图像显示的位置

前景图像是什么?
答:永远处于帧布局最上面,直接面对用户的图像,就是永远不会被覆盖的图像;

5.0之后

5.0之前和5.0之后的区别:
所以在5.0之后,就不一定都是后写的textView覆盖前些的TextView,现在的情况就是:
比如桌子上面好几张卡片,谁离桌面的距离越高,谁就在上面(出现Z轴的概念,)

// 控件离开屏幕的高度(一般小于10dp),两个属性同样的效果,默认是0dp android:elevation="5dp" android:translationZ="5dp"
<TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="第一层"        android:textColor="#f00"        android:translationZ="10dp"        android:textSize="80sp" />    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="第二层"        android:textColor="#785a5a"        android:textSize="60sp" />

效果:
我们会看到一个阴影,并且第一层会在第二层之上.
这里写图片描述

应用:
1.FrameLayout这种布局很不灵活,用处很少.
2.在API12之后,出现了FrameLayout(碎片),在定义区域的时候,会使用到FrameLayout,因为FrameLayout是ViewGroup中消耗资源最少的一个布局.

0 0
原创粉丝点击