先定义一张圆角的图片shape_bg_listview.xml
然后在ListView中引用它,注意android:listSelector为了去掉选中效果:
代码:
public class App extends Activity {
private ListView mListView = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayList list =new ArrayList();
list.add("1");
list.add("2");
list.add("3");
mListView = (ListView)findViewById(R.id.list);
mListView.setAdapter(new AppAdapter(this,list));
}
class AppAdapter extends BaseAdapter{
Context context;
ArrayList list;
AppAdapter(Context context,ArrayList list){
this.context=context;
this.list=list;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return list.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
TextView tv;
if(convertView==null){
convertView=LayoutInflater.from(context).inflate(R.layout.simple_item_2, null);
}
tv=(TextView)convertView.findViewById(R.id.name);
tv.setText(list.get(position));
return convertView;
}
}
}
simple_item_2.xml定义如下:
App列表之圆角ListView(续)
- 大小: 5.4 KB
- Test_radio.rar (58.2 KB)
- 下载次数: 215
- 查看图片附件
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net