亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

基于Android實現(xiàn)ListView圓角效果

 更新時間:2020年10月28日 14:40:14   作者:Healtheon  
這篇文章主要為大家詳細(xì)介紹了基于Android實現(xiàn)ListView圓角效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文演示如何在Android中實現(xiàn)ListView圓角效果

無論是網(wǎng)站,還是APP,人們都愛看一些新穎的視圖效果。直角看多了,就想看看圓角,這幾年刮起了一陣陣的圓角設(shè)計風(fēng):CSS新標(biāo)準(zhǔn)納入圓角元素,特別是在iphone中幾乎隨處可見圓角設(shè)計,現(xiàn)在也開始出現(xiàn)很多圓角名片了。

現(xiàn)在就給大家實現(xiàn)一個圓角的ListView效果。 圓角的設(shè)計,我們并不追求到處都用,無處不用,android中有少數(shù)界面用直角確實容易顯得鋒利,和周邊界面太過對比而顯得不協(xié)調(diào),比如大欄目列表,設(shè)置等等,而采用圓角實現(xiàn),則會活潑,輕松的多,也融合的特別好。

先看下在IPhone中實現(xiàn)圓角效果的一個圖片:

在Iphone中這種效果處處可見,但在Android中就需要我們手動實現(xiàn)了。

我們先看下示例運行效果圖,如下所示:

實現(xiàn)原理:
通過判斷ListView上點擊的項的位置,我們切換不同的選擇器,當(dāng)然這個切換的動作我們需要定義在重寫ListView的

onInterceptTouchEvent()方法中。
 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);
}

定義選擇器: 
如果只有一項,我們需要四個角都是圓角,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>

如果是頂部第一項,則上面兩個角為圓角,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>

如果是底部最后一項,則下面兩個角為圓角,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> 

如果是中間項,則應(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> 

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論