先看效果图:
首先,你得写一个类我们命名为cornerlistview
[java]
/**
* 圆角listview示例
* @description: 圆角listview示例
* @filename: cornerlistview.java
*/
public class cornerlistview extends listview {
public cornerlistview(context context) {
super(context);
}
public cornerlistview(context context, attributeset attrs, int defstyle) {
super(context, attrs, defstyle);
}
public cornerlistview(context context, attributeset attrs) {
super(context, attrs);
}
@override
public boolean onintercepttouchevent(motionevent ev) {
switch (ev.getaction()) {
case motionevent.action_down:
int x = (int) ev.getx();
int y = (int) ev.gety();
int itemnum = pointtoposition(x, y);
if (itemnum == adapterview.invalid_position)
break;
else{
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);
}
}
break;
case motionevent.action_up:
break;
}
return super.onintercepttouchevent(ev);
}
}
[html]
<?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>
[html]
<?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
[html]
<?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>
<?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>
如对本文有疑问, 点击进行留言回复!!
Error running app: Default Activity Not Found
如何用HMS Nearby Service给自己的App添加近距离数据传输功能
BlockChain:2020年7月10日世界人工智能大会WAIC《链智未来 赋能产业区块链主题论坛》(四)
网友评论