Android中FrameLayout总结

Posted baorant

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android中FrameLayout总结相关的知识,希望对你有一定的参考价值。

今天在学习实现墨迹天气那样的拖动效果时,看到用的是重写FrameLayout

FrameLayout布局是最简单的布局方式,所有添加到这个布局中的视图都是以层叠的方式显示。第一个添加到布局中视图显示在最底层,最后一个被放在最顶层。上一层的视图会覆盖下一层的视图,因此该布局类似于堆栈布局。注意点:a.默认对其方式是左上角对齐。b.若要设置子视图的位置,要设置layout_gravity属性值。

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <FrameLayout
 3     xmlns:android="http://schemas.android.com/apk/res/android"
 4     android:layout_width="fill_parent"
 5     android:layout_height="fill_parent"
 6     android:background="#897753"
 7     >
 8     <ImageView 
 9         android:id="@+id/image1"
10         android:layout_width="fill_parent"
11         android:layout_height="fill_parent"
12         android:visibility="invisible"
13         android:src="@drawable/sky"/>
14     <ImageView 
15         android:id="@+id/image2"
16         android:visibility="invisible"
17         android:layout_width="fill_parent"
18         android:layout_height="fill_parent"
19         android:src="@drawable/cloud"/>
20     <ImageView 
21         android:id="@+id/image3"
22         android:visibility="invisible"
23         android:layout_width="fill_parent"
24         android:layout_height="fill_parent"
25         android:src="@drawable/sun"/>
26 
27 </FrameLayout>

其中,image1、image2、image3都是在同一块空间的。可以说它们是重叠着的,界面显示的是最近用的那一个。

以上是关于Android中FrameLayout总结的主要内容,如果未能解决你的问题,请参考以下文章

Android:如何在 FrameLayout 元素中绘制?

Android Honeycomb:如何更改 FrameLayout 中的片段,而不重新创建它们?

Android Honeycomb:如何更改 FrameLayout 中的片段,而不重新创建它们?

为啥要使用 FrameLayout 作为 FragmentTransaction 的片段容器? [复制]

Android中FrameLayout总结

Android:FragmentManager 无法替换 FrameLayout 的问题