Android布局之FrameLayout设置控件居中显示
来源:互联网 发布:有了域名能干什么 编辑:程序博客网 时间:2024/05/22 03:30
FrameLayout帧布局,简单的说FrameLayout中的子元素总是以屏幕的左上角层叠在一起,但是,这里就存在了一个问题,如何让控件显示在屏幕的中间呢?
事实上,我们可以对子元素添加android:layout_gravity属性来设置他们的位置:
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ImageView android:id="@+id/image" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scaleType="center" android:src="@drawable/ic_launcher" /> <TextView android:id="@+id/text1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:textColor="#ff0000" android:text="你好" /> </FrameLayout>
FrameLayout布局里面android:layout_margin的各种属性必须依赖于android:layout_gravity,简单的说,要想让margin生效,必须先设置View的layout_gravity属性。
<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:layout_width="200dip" android:layout_height="wrap_content" android:orientation="vertical" android:gravity="center" android:layout_gravity="center" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="FrameLayout测试" android:textSize="13sp" android:gravity="center" /> </LinearLayout></FrameLayout>
0 1
- Android布局之FrameLayout设置控件居中显示
- Android布局之FrameLayout
- Android之FrameLayout布局
- Android-布局之FrameLayout
- android - LinearLayout、RelativeLayout、FrameLayout居中显示
- android 开发布局之FrameLayout
- Android UI布局之FrameLayout
- android布局方式之FrameLayout
- Android之FrameLayout(帧布局)
- Android之FrameLayout(帧布局)
- android 布局居中显示
- FrameLayout组件居中显示
- 《详解Android四大布局》之FrameLayout布局
- 【转载】Android布局讲解之FrameLayout布局
- Android控件居中显示
- Android布局理解之一:FrameLayout 内的控件如何设置位置
- Android布局 使控件居中
- Android初学习 - LinearLayout、RelativeLayout、FrameLayout内容居中显示
- Android中通过反射来设置Toast的显示时间
- 泛化和多态读书笔记
- GridView的三级缓存
- 【网络基础】子网划分、基于子网掩码的分组转发
- CPU cache
- Android布局之FrameLayout设置控件居中显示
- XCL-Charts画面积图(AreaChart) 例1
- Linux-网桥原理分析(一)
- 覆盖、重载、基调与原型
- 基于tomcat响应处理模型实现的高并发web服务器
- 又一版 A+B 1877
- unidac连接FireBird数据库
- maven-thrift-plugin-0.2-HPS-1.jar包下载
- OOAD系统分析视频观看笔记