gpt4 book ai didi

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

转载 作者:qq735679552 更新时间:2022-09-28 22:32:09 26 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章android开发之方形圆角listview代码分享由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

先看效果图:

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

    @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> 。

  。

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

最后此篇关于android开发之方形圆角listview代码分享的文章就讲到这里了,如果你想了解更多关于android开发之方形圆角listview代码分享的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com