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

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

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

先看效果圖:

首先,你得寫一個類我們命名為CornerListView

[java]

復(fù)制代碼 代碼如下:

/**
 * 圓角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]

復(fù)制代碼 代碼如下:

<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]

復(fù)制代碼 代碼如下:

<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]

復(fù)制代碼 代碼如下:

<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]
復(fù)制代碼 代碼如下:

<?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)用。

相關(guān)文章

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

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

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

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

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

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

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

    Android類加載流程分析

    由于前前前陣子寫了個殼,得去了解類的加載流程,當(dāng)時記了一些潦草的筆記。這幾天把這些東西簡單梳理了一下,本文分析的代碼基于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四級緩存源碼層詳細(xì)分析

    Android RecyclerView四級緩存源碼層詳細(xì)分析

    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)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-07-07
  • Android橫豎屏幕切換小結(jié)

    Android橫豎屏幕切換小結(jié)

    這篇文章主要介紹了Android橫豎屏切換小結(jié)的相關(guān)資料,需要的朋友可以參考下
    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)、平移、縮放和透明度漸變的補間動畫,本文通過實例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2018-04-04

最新評論

修文县| 青浦区| 东乡县| 清涧县| 高台县| 德江县| 衡山县| 双鸭山市| 宁波市| 竹北市| 南京市| 浦北县| 定西市| 达州市| 淳化县| 扎兰屯市| 济源市| 什邡市| 会同县| 隆安县| 宜州市| 华坪县| 民和| 大石桥市| 额济纳旗| 威海市| 涟水县| 榆社县| 苗栗市| 玉门市| 长顺县| 布拖县| 瑞安市| 宁晋县| 越西县| 萍乡市| 永春县| 克东县| 城市| 宁武县| 墨玉县|