Android FrameLayout子view居中(左居中,右居中)等
来源:互联网 发布:海拉尔二中案 知乎 编辑:程序博客网 时间:2024/06/07 05:23
Android的布局FrameLayout默认是把布局内的子view堆砌在左上角,但是,可以通过设置子view的:
android:layout_gravity
此参数控制子view的布局位置,实现FrameLayout的各种子view布局位置,如左居中,右居中,居中等等,要点在android:layout_gravity的参数设置中组合使用“center”、“left”、“right”等,现在给出XML代码实例布局:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@android:color/black" android:text="左上角" android:textColor="@android:color/white" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left|center" android:background="@android:color/black" android:text="左居中" android:textColor="@android:color/white" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:background="@android:color/black" android:text="右上角" android:textColor="@android:color/white" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right|center" android:background="@android:color/black" android:text="右居中" android:textColor="@android:color/white" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:background="@android:color/black" android:text="居中" android:textColor="@android:color/white" /></FrameLayout>
运行结果如图所示:
0 0
- Android FrameLayout子view居中(左居中,右居中)等
- Android Dialog 弹出 居右、居左、居中
- 实现字符串的对齐(左对齐、右对齐、居中)
- Android使用ViewGroup实现流式标签布局(靠左,靠右,居中)
- FrameLayout组件居中显示
- view 居中
- android - LinearLayout、RelativeLayout、FrameLayout居中显示
- 居中
- 居中
- 居中
- 居中
- 居中
- 居中
- 居中
- 居中
- 居中
- 居中
- 居中
- Android Hal 分析
- 图解正向代理、反向代理、透明代理
- 浅谈Spring事务隔离级别
- C# 中的委托和事件
- Android studio 问题与设置
- Android FrameLayout子view居中(左居中,右居中)等
- C# 反射机制
- hdu3336(KMP+DP)
- 理解几个网络硬件(调制解调器、路由器、交换机)的基本作用
- 解析 Linux 中的 VFS 文件系统机制
- 通过ant来打jar,war包
- mysql压缩版服务器安装
- MySQL清空表数据并重置Auto_increment字段起始值为1
- jQuery的ajax返回html类型不能获取片段html代码