TNBLOG
首页
博客
视频
资源
问答
猿趣
手机
关于
搜索
收藏
便签
笔记
消息
创作
登录
剑轩
故如虹,知恩;故如月,知明
博主信息
排名
6
文章
6
粉丝
16
评论
8
文章类别
CSS
15篇
微服务
41篇
Git
14篇
.NET
102篇
移动开发
33篇
软件架构
23篇
.NET Core
119篇
.NET MVC
11篇
英语
3篇
随笔
86篇
Bootstrap
3篇
Redis
21篇
编辑器
10篇
Js相关
15篇
虚拟化
8篇
更多
Oracle
7篇
Python
14篇
数据库
26篇
EF
17篇
微信
3篇
前端
151篇
消息队列
6篇
docker
41篇
多线程
1篇
Java
4篇
软件基础
2篇
C++
2篇
WCF
7篇
Linux
7篇
nginx
5篇
K8S
9篇
ABP
2篇
最新文章
最新评价
{{item.articleTitle}}
{{item.blogName}}
:
{{item.content}}
关于我们
ICP备案 :
渝ICP备18016597号-1
网站信息:
2018-2024
TNBLOG.NET
技术交流:
群号656732739
联系我们:
contact@tnblog.net
欢迎加群
欢迎加群交流技术
原
android 布局实例解析 格子菜单效果
2655
人阅读
2016/3/5 22:02
总访问:
3935435
评论:
0
收藏:
0
手机
分类:
移动开发
![](https://img.tnblog.net/arcimg/aojiancc2/1d677510865942a3b760647498fbfee2.png) 使用android权重布局,使每个格子和间隔在不同手机中自动适配: ``` <?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:background="#ffffff" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="150dp" android:background="@drawable/morebg" > </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:orientation="horizontal"> <!-- 权重布局 充当间隔 自适应所有屏幕 --> <LinearLayout android:layout_width="0dp" android:layout_weight="1" android:layout_height="60dp" > </LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_weight="10" android:layout_height="wrap_content" android:background="#f2f2f2" android:id="@+id/more_oilreports" android:gravity="center_horizontal" android:orientation="vertical"> <ImageView android:layout_width="60dp" android:layout_height="60dp" android:layout_marginTop="6dp" android:src="@drawable/more_ovil" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="油量数据报表" android:layout_marginTop="2dp" android:layout_marginBottom="3dp" /> </LinearLayout> <!-- 权重布局 充当间隔 自适应所有屏幕 --> <LinearLayout android:layout_width="0dp" android:layout_weight="1" android:layout_height="60dp" > </LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_weight="10" android:layout_height="wrap_content" android:background="#f2f2f2" android:id="@+id/linestatisticsManager" android:gravity="center_horizontal" android:orientation="vertical"> <ImageView android:layout_width="60dp" android:layout_height="60dp" android:layout_marginTop="6dp" android:src="@drawable/more_linecount" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="航次统计管理" android:layout_marginTop="2dp" android:layout_marginBottom="3dp" /> </LinearLayout> <!-- 权重布局 充当间隔 自适应所有屏幕 --> <LinearLayout android:layout_width="0dp" android:layout_weight="1" android:layout_height="60dp" > </LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_weight="10" android:background="#f2f2f2" android:layout_height="wrap_content" android:gravity="center_horizontal" android:id="@+id/moreexcetionalarm" android:orientation="vertical"> <ImageView android:layout_width="60dp" android:layout_height="60dp" android:layout_marginTop="6dp" android:src="@drawable/more_alarm" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="异常报警" android:layout_marginTop="2dp" android:layout_marginBottom="3dp" /> </LinearLayout> <!-- 权重布局 充当间隔 自适应所有屏幕 --> <LinearLayout android:layout_width="0dp" android:layout_weight="1" android:layout_height="60dp" > </LinearLayout> </LinearLayout> <!-- 第二行菜单 用margin来调整间隔还是不科学 --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:orientation="horizontal"> <!-- 权重布局 充当间隔 自适应所有屏幕 --> <LinearLayout android:layout_width="0dp" android:layout_weight="1" android:layout_height="60dp" > </LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_weight="10" android:layout_height="wrap_content" android:background="#f2f2f2" android:gravity="center_horizontal" android:id="@+id/manualaddoil" android:tag="testtag" android:orientation="vertical"> <ImageView android:layout_width="60dp" android:layout_height="60dp" android:layout_marginTop="6dp" android:src="@drawable/moretest3" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="加油上报" android:layout_marginTop="2dp" android:layout_marginBottom="3dp" /> </LinearLayout> <!-- 权重布局 充当间隔 自适应所有屏幕 --> <LinearLayout android:layout_width="0dp" android:layout_weight="1" android:layout_height="60dp" > </LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_weight="21" android:layout_height="wrap_content" android:background="#f2f2f2" android:gravity="center_horizontal" android:id="@+id/manuallossreport" android:orientation="vertical"> <ImageView android:layout_width="60dp" android:layout_height="60dp" android:layout_marginTop="6dp" android:src="@drawable/moretest2" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="损耗上报" android:layout_marginTop="2dp" android:layout_marginBottom="3dp" /> </LinearLayout> <!-- 权重布局 充当间隔 自适应所有屏幕 --> <LinearLayout android:layout_width="0dp" android:layout_weight="1" android:layout_height="60dp" > </LinearLayout> </LinearLayout> </LinearLayout> ``` 这里使用LinearLayout作为间隔比使用margin去调整要相对科学一点,能保证每个间距相同, 而且格子的第二列我们是左边宽度占一个,右边占2个,这种用margin去调整会比较麻烦,用LinearLayout去做间隔, 我们就可以计算了。上边间距占一,格子占10,下边肯定也一样,然后第二个格子的占用大小就可以用总数减去已经有了的直接得到了
欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739
👈{{preArticle.title}}
👉{{nextArticle.title}}
评价
{{titleitem}}
{{titleitem}}
{{item.content}}
{{titleitem}}
{{titleitem}}
{{item.content}}