国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

基于Android實現ListView圓角效果

2019-12-12 06:16:28
字體:
來源:轉載
供稿:網友

本文演示如何在Android中實現ListView圓角效果

無論是網站,還是APP,人們都愛看一些新穎的視圖效果。直角看多了,就想看看圓角,這幾年刮起了一陣陣的圓角設計風:CSS新標準納入圓角元素,特別是在iphone中幾乎隨處可見圓角設計,現在也開始出現很多圓角名片了。

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

先看下在IPhone中實現圓角效果的一個圖片:

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

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

實現原理:
通過判斷ListView上點擊的項的位置,我們切換不同的選擇器,當然這個切換的動作我們需要定義在重寫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> 

如果是中間項,則應該不需要圓角, 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> 

原文地址:http://www.cnblogs.com/hanyonglu/archive/2012/03/18/2404820.html

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 汉川市| 固镇县| 章丘市| 临颍县| 托克逊县| 陈巴尔虎旗| 建阳市| 定西市| 应用必备| 宁蒗| 雷波县| 杂多县| 承德市| 门头沟区| 孟州市| 龙陵县| 安龙县| 高陵县| 伊吾县| 岳普湖县| 通榆县| 莆田市| 岢岚县| 资中县| 大连市| 遵义县| 潞城市| 乐昌市| 文登市| 沽源县| 兰州市| 博野县| 金寨县| 兴山县| 比如县| 浪卡子县| 上思县| 克什克腾旗| 漳平市| 武冈市| 隆林|