xml布局内容总结(一)--Android
来源:互联网 发布:淘宝助手是干什么用的 编辑:程序博客网 时间:2024/06/06 03:55
关于安卓项目中xml的使用非常多,为了达到一些好的UI效果,需要对xml比较熟练,会使用很多的小技巧,本人准备对这些小技巧进行整理和总结,希望进行分享和交流。
关于weight的使用,由于weight在布局中主要按比例进行组件的摆放,因此比较容易解决适配的问题,所以学会使用weight会减轻开发过程中部分繁琐的开发任务。
1.使用weight居中显示
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center"
android:weightSum="1"
>
<Button
android:id="@+id/button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="Weight_Button" />
</LinearLayout>
2.使用weight实现相同宽度的n个组件(这里用3个做测试)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="3"
>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Weight_Button1" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Weight_Button2" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Weight_Button3" />
</LinearLayout>
3.使用weight实现不同比例宽度的n个组件(这里用4个做测试)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="10"
>
<TextView
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="4"
android:background="@color/yellow"
android:text="4" />
<TextView
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="3"
android:background="@color/red"
android:text="3" />
<TextView
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="2"
android:background="@color/yellow"
android:text="2" />
<TextView
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="1"
android:background="@color/red"
android:text="1" />
</LinearLayout>
占据比例分别为总宽度的0.4,0.3,0.2,0.1
- xml布局内容总结(一)--Android
- xml布局内容总结(二)--Android
- xml布局内容总结(三)--Android
- xml布局内容总结(四)--Android
- 【android-tips】android xml布局总结篇
- 【android-tips】android xml布局总结篇
- Android开发的xml布局文件属性总结
- Android中Xml布局常见属性总结
- Android布局总结一:GridLayout布局(网格布局)
- XML总结(一)
- xml总结(一)
- css布局总结(一)
- Android布局管理器总结一:LinearLayout
- 指针内容总结(一)
- Xml布局常见问题总结
- Android开发---xml布局文件中的常见属性总结
- Android开发---xml布局文件中的常见属性总结
- Android开发---xml布局文件中的常见属性总结
- VS2015, .NET 4.6, C# 6.0, F# 4.0等重量级产品正式上线
- web.xml错误处理
- Java-发送邮件(附件、图片)---(一)概述
- 【工作拾遗】 weblogic节点服务启动问题记录
- 分解复杂判断
- xml布局内容总结(一)--Android
- [LeetCode][Java] Minimum Depth of Binary Tree
- 引入参数对象
- Apache Web Server -> httpd 的虚拟主机的配置
- 栈帧、局部变量表、操作数栈
- 笔试题程序练习
- Android Studio SDK 更新问题
- C++中static关键字的总结
- jquery模拟select