Frame Layout
来源:互联网 发布:淘宝差评被报复怎么办 编辑:程序博客网 时间:2024/05/16 16:11
FrameLayout
这种布局会为每个加入其中的组件创建一个空白的区域,即为一帧,每个子组件占据一帧。
FrameLayout包含的子元素受FrameLayout_LayoutParams控制,因此当我们往里面添加组件的时候,所有的组件都会放置于这块区域的左上角,而帧布局的大小由子控件中最大的子控件决定。
这个布局的属性很简单,下面举两个例子
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="50sp" android:text="@string/world_peace"/></FrameLayout>
效果图:
同时,我们也可以为组件添加layout_gravity属性,从而指定组件的对齐方式,如下可见。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:width="170pt" android:height="170pt" android:background="#ff0"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:width="140pt" android:height="140pt" android:background="#f0f"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:width="110pt" android:height="110pt" android:background="#0ff"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:width="80pt" android:height="80pt" android:background="#f00"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:width="50pt" android:height="50pt" android:background="#0f0"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:width="20pt" android:height="20pt" android:background="#00f"/></FrameLayout>
效果图
这里将所有的TextView的layout_gravity属性设置为center。并且将后添加的图片宽高逐渐减小,避免了最先添加的TextView被完全遮挡。
注:知识点参考自Android官方文档及《疯狂Android讲义》/李刚
0 0
- Frame Layout
- ARM Stack Frame Layout
- Android帧布局(Frame Layout)
- 【Android】Tween/Layout/Frame动画
- 五大属性之Frame & absolute Layout
- iOS7 采用 Auto Layout后获取frame
- Assembly x64 Intro - Stack frame layout on x86-64
- 使用 Auto Layout 之后什么时候才能获得正确的 frame?
- frame
- frame
- frame
- Frame
- Frame
- frame
- Frame
- frame
- frame
- Frame
- 观“当幸福来敲门”有感
- 测试过程中一些特殊问题的处理方式
- linux常用命令(62):watch命令
- .NET整合及绿色软件工具VMThinApp使用
- JavaAPI_String
- Frame Layout
- 软件测试中的那些基础知识
- 很有道理的程序员的小故事
- 惠普实训第一阶段完结
- mysql CURRENT_TIMESTAMP 和ON UPDATE CURRENT_TIMESTAMP
- navicat远程连接oracle遇到的一点点小问题
- jquery mobile 数字键盘类似计算器的布局采用Grid实现
- poj-1741(树分治 点权)
- Arduino debug 实时单步调试.