最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

android開發(fā)之方形圓角listview代碼分享

 更新時間:2013年06月03日 10:51:56   作者:  
我寫這篇文章受到了kiritor的專欄發(fā)表的博文Android UI控件之ListView實現(xiàn)圓角效果的啟發(fā)。

先看效果圖:

首先,你得寫一個類我們命名為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一樣調(diào)用。

相關文章

  • Android開發(fā)之OkHttpUtils的具體使用方法

    Android開發(fā)之OkHttpUtils的具體使用方法

    這篇文章主要介紹了Android開發(fā)之OkHttpUtils的具體使用方法,非常具有實用價值,需要的朋友可以參考下
    2017-08-08
  • flutter實現(xiàn)底部不規(guī)則導航欄

    flutter實現(xiàn)底部不規(guī)則導航欄

    這篇文章主要為大家詳細介紹了flutter實現(xiàn)底部不規(guī)則導航欄,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-07-07
  • Android如何動態(tài)調(diào)整應用字體大小詳解

    Android如何動態(tài)調(diào)整應用字體大小詳解

    這篇文章主要給大家介紹了關于Android如何動態(tài)調(diào)整應用字體大小的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2018-05-05
  • Android類加載流程分析

    Android類加載流程分析

    由于前前前陣子寫了個殼,得去了解類的加載流程,當時記了一些潦草的筆記。這幾天把這些東西簡單梳理了一下,本文分析的代碼基于Android8.1.0源碼,感興趣的朋友跟隨小編一起看看吧
    2022-10-10
  • C/C++在Java、Android和Objective-C三大平臺下實現(xiàn)混合編程

    C/C++在Java、Android和Objective-C三大平臺下實現(xiàn)混合編程

    本文主要介紹C/C++在Java、Android和Objective-C三大平臺下實現(xiàn)混合編程,這里舉例說明實現(xiàn)不同平臺用C/C++實現(xiàn)編程的方法,有興趣的小伙伴可以參考下
    2016-08-08
  • Android RecyclerView四級緩存源碼層詳細分析

    Android RecyclerView四級緩存源碼層詳細分析

    RecyclerView是Android一個更強大的控件,其不僅可以實現(xiàn)和ListView同樣的效果,還有優(yōu)化了ListView中的各種不足。其可以實現(xiàn)數(shù)據(jù)縱向滾動,也可以實現(xiàn)橫向滾動(ListView做不到橫向滾動)。接下來講解RecyclerView的用法
    2022-11-11
  • RecyclerView多層級數(shù)據(jù)實現(xiàn)示例詳解

    RecyclerView多層級數(shù)據(jù)實現(xiàn)示例詳解

    這篇文章主要為大家介紹了RecyclerView多層級數(shù)據(jù)實現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-07-07
  • Android橫豎屏幕切換小結

    Android橫豎屏幕切換小結

    這篇文章主要介紹了Android橫豎屏切換小結的相關資料,需要的朋友可以參考下
    2016-02-02
  • Flutter RSA加密解密的示例代碼

    Flutter RSA加密解密的示例代碼

    數(shù)據(jù)加密有對稱加密(對稱密鑰方案) 和非對稱加密(公鑰加密) 兩種加密方式,本文主要介紹了Flutter RSA加密解密的示例代碼,感興趣的可以了解一下
    2022-04-04
  • Android旋轉(zhuǎn)、平移、縮放和透明度漸變的補間動畫

    Android旋轉(zhuǎn)、平移、縮放和透明度漸變的補間動畫

    這篇文章主要實現(xiàn)Android旋轉(zhuǎn)、平移、縮放和透明度漸變的補間動畫,本文通過實例代碼給大家介紹的非常詳細,需要的朋友可以參考下
    2018-04-04

最新評論

望城县| 高州市| 民和| 永胜县| 西丰县| 宁陵县| 仪陇县| 周口市| 抚松县| 建德市| 靖边县| 江口县| 定远县| 若尔盖县| 庆城县| 元朗区| 天等县| 郧西县| 和林格尔县| 临夏县| 连江县| 九龙城区| 晋江市| 新疆| 轮台县| 杭锦后旗| 桂东县| 珠海市| 玉溪市| 雅安市| 庄浪县| 芷江| 张掖市| 霍州市| 凤台县| 漳州市| 林西县| 永定县| 博乐市| 乐至县| 密山市|