zoukankan      html  css  js  c++  java
  • android开发之方形圆角listview

    我写这篇文章受到了kiritor的专栏发表的博文Android UI控件之ListView实现圆角效果的启发。

    先看效果图:


    首先,你得写一个类我们命名为CornerListView

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

    其中,app_list_corner_round

    <?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 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 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 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一样调用。


  • 相关阅读:
    随便玩玩Microsoft Test Manager
    SharePoint 2013 安装指南
    使用Napa开发工具创建app 开始构建SharePoint app系列
    Displaying files from a specific folder using SPDataSource
    当把鼠标放上去以后呈手型代码
    asp.net中嵌入日历控件代码
    ado.net中带有用户名及密码的数据库连接字符串
    用OnClientClick事件中实现跳转
    asp.net中生成动态验证码代码
    asp.net中加入收藏及设为首页代码
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3098740.html
Copyright © 2011-2022 走看看