android开发之方形圆角listview代码分享

三里屯的土耗子

三里屯的土耗子

2016-02-19 09:26

想要天天向上,就要懂得享受学习。图老师为大家推荐android开发之方形圆角listview代码分享,精彩的内容需要你们用心的阅读。还在等什么快点来看看吧!

先看效果图:

首先,你得写一个类我们命名为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.SPAN style="COLOR: #ff0000"app_list_corner_round/SPAN);
                        }else{
                            setSelector(R.drawable.SPAN style="COLOR: #ff0000"app_list_corner_round_top/SPAN);
                        }
                    }else if(itemnum==(getAdapter().getCount()-1))
                            setSelector(R.drawable.SPAN style="COLOR: #ff0000"app_list_corner_round_bottom/SPAN);
                    else{                            
                        setSelector(R.drawable.SPAN style="COLOR: #ff0000"app_list_corner_shape/SPAN);
                    }
                }

                break;
        case MotionEvent.ACTION_UP:
                break;
        }

        return super.onInterceptTouchEvent(ev);
    }
}

/**
 * 圆角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);
    }

(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)

    @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);
    }
}


其中,app_list_corner_round

[html]

代码如下:

SPAN style="COLOR: #333333"?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 /SPAN

(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)

?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

[html]
代码如下:

SPAN style="COLOR: #333333"?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 /SPAN

?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]
代码如下:

SPAN style="COLOR: #333333"?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 /SPAN

?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
[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"/
/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


写好了之后,就可以在你的代码中直接像listview一样调用。

展开更多 50%)
分享

猜你喜欢

android开发之方形圆角listview代码分享

编程语言 网络编程
android开发之方形圆角listview代码分享

android panellistview 圆角实现代码

编程语言 网络编程
android panellistview 圆角实现代码

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

android开发之横向滚动/竖向滚动的ListView(固定列头)

编程语言 网络编程
android开发之横向滚动/竖向滚动的ListView(固定列头)

基于Android ListView之加载使用技巧

编程语言 网络编程
基于Android ListView之加载使用技巧

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

android ListView和GridView拖拽移位实现代码

编程语言 网络编程
android ListView和GridView拖拽移位实现代码

Android在listview添加checkbox实现原理与代码

编程语言 网络编程
Android在listview添加checkbox实现原理与代码

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

Javascript注入技巧

Javascript注入技巧

下辈子莪要做洋葱 - QQ非主流分组

下辈子莪要做洋葱 - QQ非主流分组
下拉加载更多内容 ↓