基于Android實(shí)現(xiàn)ListView圓角效果
本文演示如何在Android中實(shí)現(xiàn)ListView圓角效果。
無(wú)論是網(wǎng)站,還是APP,人們都愛(ài)看一些新穎的視圖效果。直角看多了,就想看看圓角,這幾年刮起了一陣陣的圓角設(shè)計(jì)風(fēng):CSS新標(biāo)準(zhǔn)納入圓角元素,特別是在iphone中幾乎隨處可見(jiàn)圓角設(shè)計(jì),現(xiàn)在也開(kāi)始出現(xiàn)很多圓角名片了。
現(xiàn)在就給大家實(shí)現(xiàn)一個(gè)圓角的ListView效果。 圓角的設(shè)計(jì),我們并不追求到處都用,無(wú)處不用,android中有少數(shù)界面用直角確實(shí)容易顯得鋒利,和周邊界面太過(guò)對(duì)比而顯得不協(xié)調(diào),比如大欄目列表,設(shè)置等等,而采用圓角實(shí)現(xiàn),則會(huì)活潑,輕松的多,也融合的特別好。
先看下在IPhone中實(shí)現(xiàn)圓角效果的一個(gè)圖片:
在Iphone中這種效果處處可見(jiàn),但在Android中就需要我們手動(dòng)實(shí)現(xiàn)了。
我們先看下示例運(yùn)行效果圖,如下所示:
實(shí)現(xiàn)原理:
通過(guò)判斷ListView上點(diǎn)擊的項(xiàng)的位置,我們切換不同的選擇器,當(dāng)然這個(gè)切換的動(dòng)作我們需要定義在重寫(xiě)ListView的
onInterceptTouchEvent()方法中。 if(itemnum==0){ if(itemnum==(getAdapter().getCount()-1)){ //只有一項(xiàng) setSelector(R.drawable.app_list_corner_round); }else{ //第一項(xiàng) setSelector(R.drawable.app_list_corner_round_top); } }else if(itemnum==(getAdapter().getCount()-1)) //最后一項(xiàng) setSelector(R.drawable.app_list_corner_round_bottom); else{ //中間一項(xiàng) setSelector(R.drawable.app_list_corner_shape); }
定義選擇器:
如果只有一項(xiàng),我們需要四個(gè)角都是圓角,app_list_corner_round.xml文件定義如下:
<?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>
如果是頂部第一項(xiàng),則上面兩個(gè)角為圓角,app_list_corner_round_top.xml定義如下:
<?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>
如果是底部最后一項(xiàng),則下面兩個(gè)角為圓角,app_list_corner_round_bottom.xml定義如下:
<?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>
如果是中間項(xiàng),則應(yīng)該不需要圓角, app_list_corner_shape.xml定義如下:
<?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>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android Studio三方引用報(bào)錯(cuò)但是項(xiàng)目可以運(yùn)行的解決方案
今天小編就為大家分享一篇關(guān)于Android Studio三方引用報(bào)錯(cuò)但是項(xiàng)目可以運(yùn)行的解決方案,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2019-03-03Android自定義View實(shí)現(xiàn)可以拖拽的GridView
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)可以拖拽的GridView,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-06-06Rxjava+Retrofit+Okhttp進(jìn)行網(wǎng)絡(luò)訪(fǎng)問(wèn)及數(shù)據(jù)解析
這篇文章主要介紹了Rxjava+Retrofit+Okhttp進(jìn)行網(wǎng)絡(luò)訪(fǎng)問(wèn)及數(shù)據(jù)解析,文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,感興趣的小伙伴可以參考一下2022-08-08Android使用Xutils3進(jìn)行斷點(diǎn)下載的實(shí)例
在本篇內(nèi)容中小編給各位整理了關(guān)于Android使用Xutils3進(jìn)行斷點(diǎn)下載的實(shí)例以及相關(guān)代碼,需要的朋友們參考下。2019-07-07Android UI設(shè)計(jì)系列之HTML標(biāo)簽實(shí)現(xiàn)TextView設(shè)置中文字體加粗效果(6)
這篇文章主要介紹了Android UI設(shè)計(jì)系列之使用HTML標(biāo)簽,實(shí)現(xiàn)在TextView中對(duì)中文字體加粗的效果,具有一定的實(shí)用性和參考價(jià)值,感興趣的小伙伴們可以參考一下2016-06-06Flutter多項(xiàng)選擇彈窗實(shí)現(xiàn)詳解
這篇文章介紹了Flutter多項(xiàng)選擇彈窗實(shí)現(xiàn)詳解,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧<BR>2021-11-11Android學(xué)習(xí)之AppWidget高級(jí)效果
這篇文章主要為大家詳細(xì)介紹了Android學(xué)習(xí)之AppWidget高級(jí)效果的相關(guān)資料,感興趣的小伙伴們可以參考一下2016-08-08Android編程實(shí)現(xiàn)將tab選項(xiàng)卡放在屏幕底部的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)將tab選項(xiàng)卡放在屏幕底部的方法,涉及Android界面布局、tab設(shè)置及權(quán)限控制相關(guān)操作技巧,需要的朋友可以參考下2017-03-03Android中ImageView實(shí)現(xiàn)選擇本地圖片并顯示功能
本文主要介紹了android中ImageView實(shí)現(xiàn)選擇本地圖片并顯示功能的示例代碼。具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧2017-04-04