Android自定义ViewGroup实现九宫格布局
作者:newki 时间:2023-09-03 20:59:33
前言
在之前的文章我们复习了 ViewGroup 的测量与布局,那么我们这一篇效果就可以在之前的基础上实现一个灵活的九宫格布局。
那么一个九宫格的 ViewGroup 如何定义,我们分解为如下的几个步骤来实现:
先计算与测量九宫格内部的子View的宽度与高度。
再计算整体九宫格的宽度和高度。
进行子View九宫格的布局。
对单独的图片和四宫格的图片进行单独的布局处理
对填充的子View的方式进行抽取,可以自由添加布局。
对自定义属性的抽取,设置通用的属性。
只要在前文的基础上掌握了 ViewGroup 的测量与布局,其实实现起来一点都不难,甚至我们还能实现一些特别的效果。
来源:https://juejin.cn/post/7175085561538379833
标签:Android,ViewGroup,九宫格
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
如何使用Java爬虫批量爬取图片
2023-01-11 16:19:54
![](https://img.aspxhome.com/file/2023/4/114054_0s.png)
Maven之导入thymeleaf依赖飘红问题及解决
2023-11-12 12:49:05
![](https://img.aspxhome.com/file/2023/0/79920_0s.png)
浅析C# 结构体struct
2021-08-08 08:21:19
Android毕业设计备忘录APP
2023-12-25 02:28:17
![](https://img.aspxhome.com/file/2023/3/111733_0s.jpg)
Java中ArrayList和LinkedList区别
2023-09-06 20:43:09
Android Gradle模块依赖替换使用技巧
2021-07-03 20:22:53
![](https://img.aspxhome.com/file/2023/0/138170_0s.jpg)
java泛型基本知识和通用方法
2023-09-19 12:59:12
在Unity中使用全局变量的操作
2022-12-30 13:18:47
![](https://img.aspxhome.com/file/2023/0/119550_0s.jpg)
基于C#实现乱码视频效果
2022-01-25 14:29:56
![](https://img.aspxhome.com/file/2023/8/98218_0s.png)
Redisson延迟队列执行流程源码解析
2021-12-07 12:03:46
![](https://img.aspxhome.com/file/2023/3/70353_0s.png)
Android标题栏最右边添加按钮的实例
2021-08-09 07:08:07
![](https://img.aspxhome.com/file/2023/8/109168_0s.png)
Android自定义控件基本原理详解(一)
2022-05-02 12:29:32
![](https://img.aspxhome.com/file/2023/1/123231_0s.jpg)
Java中的匿名内部类小结
2021-05-29 06:29:38
![](https://img.aspxhome.com/file/2023/0/66700_0s.png)
Java深入浅出数组的定义与使用上篇
2022-03-10 22:32:58
![](https://img.aspxhome.com/file/2023/1/67131_0s.png)
spring boot如何实现切割分片上传
2023-06-29 02:49:26
![](https://img.aspxhome.com/file/2023/7/57487_0s.png)
Android自定义View实现通讯录字母索引(仿微信通讯录)
2023-05-14 04:34:22
![](https://img.aspxhome.com/file/2023/5/118965_0s.png)
使用 BenchmarkDotNet 对 C# 代码进行基准测试
2023-06-25 00:38:49
![](https://img.aspxhome.com/file/2023/7/72487_0s.png)
C#中static静态变量的用法实例
2022-12-16 07:47:44
C#实现文件筛选读取并翻译的自动化工具
2021-11-07 18:49:46
![](https://img.aspxhome.com/file/2023/1/106521_0s.png)
android实现倒计时功能代码
2022-06-28 03:57:31
![](https://img.aspxhome.com/file/2023/4/123354_0s.png)