怎样实现IOS圆角风格的列表ListView

这段代码目前已经加在我的一个jar包androidkit中,还没发布。
适用于android1.6以上,不依赖其他jar包

使用时不需要继承这里的RoundListAdapter。只需要在你实现了ListAdapter的类中,传入一个RoundParams的对象,并在getView方法返回前调用这里RoundListAdapter类提供的静态方法。
RoundListAdapter.setItemBackground(position, switcherView, mParams,

getCount());


01 /*
02 * @(#)RoundListAdapter.java Project:com.sinaapp.msdxblog.androidkit
03 * Date:2012-12-6
04 *
05 * Copyright (c) 2011 CFuture09, Institute of Software,
06 * Guangdong Ocean University, Zhanjiang, GuangDong, China.
07 * All rights reserved.
08 *
09 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21 package com.lurencun.cfuture09.androidkit.widget.roundlist;
22
23 import android.view.View;
24 import android.widget.ListAdapter;
25
26 /**
27 * @author Geek_Soledad (66704238@51uc.com)
28 */
29 public abstract class RoundListAdapter implements ListAdapter {
30 /**
31 * 圆角ListView的参数类。定义了顶部背景,底部背景,中间背景及单独一个时的背景。
32 *
33 * @author msdx
34 *
35 */
36 publicstaticclassRoundParams {
37 publicinttopResid;
38 publicintmiddleResid;
39 publicintbottomResid;
40 publicintlonelyResid;
41
42 publicRoundParams(inttopResid,intmiddleReside,intbottomResid,
43 intlonelyResid) {
44 this.topResid = topResid;
45 this.middleResid = middleReside;
46 this.bottomResid = bottomResid;
47 this.lonelyResid = lonelyResid;
48 }
49 }
50
51 publicstaticvoidsetItemBackground(intposition, View item,
52 finalRoundParams mParams,finalintcount) {
53 if(count ==1) {
54 item.setBackgroundResource(mParams.lonelyResid);
55 }elseif(position >0&& position < count -1) {
56 item.setBackgroundResource(mParams.middleResid);
57 }elseif(position ==0) {
58 item.setBackgroundResource(mParams.topResid);
59 }else{
60 item.setBackgroundResource(mParams.bottomResid);
61 }
62 }
63 }

2.[代码]使用示例

01 /*
02 * @(#)LocalAdapter.java Project:RTKSETTINGS
03 * Date:2013-1-9
04 *
05 * Copyright (c) 2013 Geek_Soledad.
06 * All rights reserved.
07 *
08 * Licensed under the Apache License, Version 2.0 (the "License");
09 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20 package com.realtek.msdx.rtksettings.view;
21
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import android.app.TvManager;
26 import android.content.Context;
27 import android.view.View;
28 import android.view.ViewGroup;
29 import android.widget.BaseAdapter;
30
31 import com.lurencun.cfuture09.androidkit.widget.roundlist.RoundListAdapter;
32 import com.lurencun.cfuture09.androidkit.widget.roundlist.RoundListAdapter.RoundParams;
33 import com.realtek.msdx.rtksettings.activity.MainActivity;
34 import com.realtek.msdx.rtksettings.bean.LocalSettingsBean;
35
36 /**
37 * @author Geek_Soledad (msdx.android@tom.com)
38 */
39 publicclassLocalAdapterextendsBaseAdapter {
40
41 privateRoundParams mParams;
42 privateContext mContext;
43
44 publicLocalAdapter(Context context, RoundParams params) {
45 super();
46 mContext = context;
47 mParams = params;
48 }
49
50 @Override
51 publicintgetCount() {
52 return5;
53 }
54
55 @Override
56 publicObject getItem(intposition) {
57 returnposition;
58 }
59
60 @Override
61 publiclonggetItemId(intposition) {
62 returnposition;
63 }
64
65 @Override
66 publicView getView(intposition, View convertView, ViewGroup parent) {
67 // 在这里创建view,
68 //SwitcherTextView view = new SwitcherTextView(mContext);
69 // 然后在返回view前进行调用
70 RoundListAdapter.setItemBackground(position, view, mParams,
71 getCount());
72 returnview;
73 }
74 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值