ListView圆角实现

摘要:
此处使用用户定义的控件,以及用户定义的ListViewpackagecom.example。演示;importandroid内容。上下文导入roid.util。属性集;importandroid视图。运动事件;importandroid.widget。适配器视图;importandroid.widget.ListVie

ListView圆角实现第1张

这里用到了自定义控件,自定义ListView

package com.example.demo;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.AdapterView;
import android.widget.ListView;

/**
 * 圆角ListView
 */
public class ListCorn extends ListView {

    public ListCorn(Context context) {
        this(context, null);
    }

    public ListCorn(Context context, AttributeSet attrs) {
        super(context, attrs);
        //整个listview的圆角背景
        this.setBackgroundResource(R.drawable.corner_list_bg);
    }

    @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.corner_list_single_item);
                                } else {
                                    //第一项
                                    setSelector(R.drawable.corner_list_first_item);
                                }
                        } else if (itemnum==(getAdapter().getCount()-1)){
                             //最后一项
                            setSelector(R.drawable.corner_list_last_item);
                        } else {
                            //中间项
                            setSelector(R.drawable.corner_list_item);
                        }
                }
                break;
        case MotionEvent.ACTION_UP:
                break;
        }
        return super.onInterceptTouchEvent(ev);
    }
}

然后在布局文件中应用

 <com.example.demo.ListCorn
      android:id="@+id/ydlist"android:layout_below="@+id/edit"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:layout_centerHorizontal="true"android:layout_margin="10dp"android:cacheColorHint="#00000000"android:scrollbars="none" >
  </com.example.demo.ListCorn>

免责声明:文章转载自《ListView圆角实现》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇目标检测相关基础概念java的VO和PO的用途下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Xamarin.Forms Layout Challenges – Timeline(转载,已翻译)

翻译采用中英对照的方式. 原文地址:http://www.kymphillpotts.com/xamarin-forms-layout-challenges-timeline/ Github地址:https://github.com/kphillpotts/XamarinFormsLayoutChallenges/tree/master/Timeline...

C#winform中ListView的使用

使用ListView模仿Windows系统的资源管理器界面,实现文件(夹)的浏览、重命名、删除及查询等功能,主要功能界面展示如下: 1.MainForm.cs及MainForm.Designer.cs 1 using System; 2 using System.Collections.Generic; 3 using System....

Android中ListView的总结(1)

这ListView真是麻烦,一个小小的FileBrowser废了将近2天。看来自己的功力还需要加强。 做FileBrowser中遇到几个ListView问题总结一下。 1、自定义样式   ListView其实和Asp.net里面的Repeater有点像,但是不同的是项的内容可以用一个layout文件来套用,这个比较有意思,毕竟刚开始研究android姑且叫...

Android学习笔记(20)————利用ListView制作带竖线的多彩表格

http://blog.csdn.net/conowen/article/details/7421805 /********************************************************************************************* author:conowen@大钟 * E-mail:cono...

项目经理打分

02章《深入C#数据类型》项目经理评分   一:创建MyOffices项目,创建UserInfo类,用来存储员工 工号,姓名,年龄,评价,年度得分 二:创建查看评分窗体(frmShow),添加定义员工数组,将员工数据绑定到frmShow窗体的ListView控件上。运行结果如下: 实现思路: 长度为3的UserInfo类型数组,并初始化数组、赋值...

ListView数据动态更新

      经常会用到数据与前台控件绑定相关的问题,一直知道要用委托(代理)但每次都忘,而且每次都百度了一遍又一遍,就是不长记性,这次一定好好记下来下次就不会忘了。       后台数据与前台绑定主要分为两步:       第一步把要绑定的数据定义为一个数据集合或对象绑定到List中,方便调用: public class TestCase:INotifyP...