Android 台灣中文網
標題:
實現IOS圓角風格的列表ListView
[打印本頁]
作者:
暗桌之光
時間:
2013-7-3 16:04
標題:
實現IOS圓角風格的列表ListView
這段代碼目前已經加在我的一個jar包androidkit中,還沒發佈。
適用於android1.6以上,不依賴其他jar包
使用時不需要繼承這裡的RoundListAdapter。只需要在你實現了ListAdapter的類中,傳入一個RoundParams的對象,並在getView方法返回前調用這裡RoundListAdapter類提供的靜態方法。
RoundListAdapter.setItemBackground(position, switcherView, mParams,
getCount());
/*
* @(#)RoundListAdapter.java Project:com.sinaapp.msdxblog.androidkit
* Date:2012-12-6
*
* Copyright (c) 2011 CFuture09, Institute of Software,
* Guangdong Ocean University, Zhanjiang, GuangDong, China.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.lurencun.cfuture09.androidkit.widget.roundlist;
import android.view.View;
import android.widget.ListAdapter;
/**
* @author Geek_Soledad (
[email protected]
)
*/
public abstract class RoundListAdapter implements ListAdapter {
/**
* 圓角ListView的參數類。定義了頂部背景,底部背景,中間背景及單獨一個時的背景。
*
* @author msdx
*
*/
public static class RoundParams {
public int topResid;
public int middleResid;
public int bottomResid;
public int lonelyResid;
public RoundParams(int topResid, int middleReside, int bottomResid,
int lonelyResid) {
this.topResid = topResid;
this.middleResid = middleReside;
this.bottomResid = bottomResid;
this.lonelyResid = lonelyResid;
}
}
public static void setItemBackground(int position, View item,
final RoundParams mParams, final int count) {
if (count == 1) {
item.setBackgroundResource(mParams.lonelyResid);
} else if (position > 0 && position < count - 1) {
item.setBackgroundResource(mParams.middleResid);
} else if (position == 0) {
item.setBackgroundResource(mParams.topResid);
} else {
item.setBackgroundResource(mParams.bottomResid);
}
}
}
複製代碼
/*
* @(#)LocalAdapter.java Project:RTKSETTINGS
* Date:2013-1-9
*
* Copyright (c) 2013 Geek_Soledad.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.realtek.msdx.rtksettings.view;
import java.util.ArrayList;
import java.util.List;
import android.app.TvManager;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import com.lurencun.cfuture09.androidkit.widget.roundlist.RoundListAdapter;
import com.lurencun.cfuture09.androidkit.widget.roundlist.RoundListAdapter.RoundParams;
import com.realtek.msdx.rtksettings.activity.MainActivity;
import com.realtek.msdx.rtksettings.bean.LocalSettingsBean;
/**
* @author Geek_Soledad (
[email protected]
)
*/
public class LocalAdapter extends BaseAdapter {
private RoundParams mParams;
private Context mContext;
public LocalAdapter(Context context, RoundParams params) {
super();
mContext = context;
mParams = params;
}
@Override
public int getCount() {
return 5;
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// 在這裡建立view,
//SwitcherTextView view = new SwitcherTextView(mContext);
// 然後在返回view前進行調用
RoundListAdapter.setItemBackground(position, view, mParams,
getCount());
return view;
}
}
複製代碼
歡迎光臨 Android 台灣中文網 (https://apk.tw/)
Powered by Discuz! X3.1