基于Android实现ListView圆角效果
作者:Healtheon 时间:2022-01-18 01:40:33
本文演示如何在Android中实现ListView圆角效果。
无论是网站,还是APP,人们都爱看一些新颖的视图效果。直角看多了,就想看看圆角,这几年刮起了一阵阵的圆角设计风:CSS新标准纳入圆角元素,特别是在iphone中几乎随处可见圆角设计,现在也开始出现很多圆角名片了。
现在就给大家实现一个圆角的ListView效果。 圆角的设计,我们并不追求到处都用,无处不用,android中有少数界面用直角确实容易显得锋利,和周边界面太过对比而显得不协调,比如大栏目列表,设置等等,而采用圆角实现,则会活泼,轻松的多,也融合的特别好。
先看下在IPhone中实现圆角效果的一个图片:
在Iphone中这种效果处处可见,但在Android中就需要我们手动实现了。
我们先看下示例运行效果图,如下所示:
实现原理:
通过判断ListView上点击的项的位置,我们切换不同的选择器,当然这个切换的动作我们需要定义在重写ListView的
onInterceptTouchEvent()方法中。
if(itemnum==0){
if(itemnum==(getAdapter().getCount()-1)){
//只有一项
setSelector(R.drawable.app_list_corner_round);
}else{
//第一项
setSelector(R.drawable.app_list_corner_round_top);
}
}else if(itemnum==(getAdapter().getCount()-1))
//最后一项
setSelector(R.drawable.app_list_corner_round_bottom);
else{
//中间一项
setSelector(R.drawable.app_list_corner_shape);
}
定义选择器:
如果只有一项,我们需要四个角都是圆角,app_list_corner_round.xml文件定义如下:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:startColor="#BFEEFF"
android:endColor="#40B9FF"
android:angle="270"/>
<corners android:topLeftRadius="6dip"
android:topRightRadius="6dip"
android:bottomLeftRadius="6dip"
android:bottomRightRadius="6dip"/>
</shape>
如果是顶部第一项,则上面两个角为圆角,app_list_corner_round_top.xml定义如下:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:startColor="#BFEEFF"
android:endColor="#40B9FF"
android:angle="270"/>
<corners android:topLeftRadius="6dip"
android:topRightRadius="6dip"/>
</shape>
如果是底部最后一项,则下面两个角为圆角,app_list_corner_round_bottom.xml定义如下:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:startColor="#BFEEFF"
android:endColor="#40B9FF"
android:angle="270"/>
<corners android:bottomLeftRadius="6dip"
android:bottomRightRadius="6dip" />
</shape>
如果是中间项,则应该不需要圆角, app_list_corner_shape.xml定义如下:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:startColor="#BFEEFF"
android:endColor="#40B9FF"
android:angle="270"/>
</shape>
标签:Android,ListView,圆角
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java String类字符串的理解与认知
2022-05-10 17:27:12
![](https://img.aspxhome.com/file/2023/5/60825_0s.png)
spring boot actuator监控超详细教程
2021-06-27 01:29:36
![](https://img.aspxhome.com/file/2023/3/94293_0s.png)
java实现解析二进制文件的方法(字符串、图片)
2023-04-18 19:07:51
Java工程中使用Mybatis (工程结合Mybatis,数据结合Swing使用))
2023-05-27 11:52:38
![](https://img.aspxhome.com/file/2023/8/78038_0s.png)
C#操作XML文件步骤
2021-11-04 21:51:44
![](https://img.aspxhome.com/file/2023/3/76433_0s.png)
详细总结Java for循环的那些坑
2023-04-23 16:35:05
基于Spring Boot不同的环境使用不同的配置方法
2022-11-06 13:21:20
C#中DataSet转化为实体集合类的方法
2022-05-09 00:50:46
Android开发中的重力传感器用法实例详解
2022-01-28 12:57:01
![](https://img.aspxhome.com/file/2023/1/96801_0s.jpg)
C#实现PDF文件添加图片背景
2022-04-03 20:45:35
java和c/c++ 数据类型长度的比较
2021-06-18 00:07:45
Java 8实现图片BASE64编解码
2022-08-22 05:35:05
![](https://img.aspxhome.com/file/2023/1/68521_0s.png)
Java实战之飞翔的小鸟小游戏
2022-10-04 20:37:20
![](https://img.aspxhome.com/file/2023/3/63483_0s.png)
Java JDK动态代理实现原理实例解析
2022-04-23 05:19:10
详解Java中的Lambda表达式
2023-06-05 01:37:16
Java 多线程同步 锁机制与synchronized深入解析
2023-12-20 17:55:50
Android Studio实现简易计算器(表格布局TableLayout)
2021-11-17 23:20:07
![](https://img.aspxhome.com/file/2023/4/98624_0s.jpg)
Java输入/输出流体系详解
2023-03-01 06:37:00
![](https://img.aspxhome.com/file/2023/9/65739_0s.png)
Java异步调用转同步方法实例详解
2023-11-01 20:38:25
Spring运行时动态注册bean的方法
2023-11-25 04:16:58