圆角背景的ListView
系统
1767 0
先定义一张圆角的图片shape_bg_listview.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<gradient
android:startColor="@android:color/white"
android:endColor="#FFCCCCCC"
android:angle="180"
/>
<stroke android:width="0px"
android:color="@android:color/white"
/>
<solid android:color="@android:color/white"
/>
<corners
android:bottomRightRadius="20px"
android:bottomLeftRadius="20px"
android:topLeftRadius="20px"
android:topRightRadius="20px"
/>
</shape>
然后在ListView中引用它,注意android:listSelector为了去掉选中效果:
<ListView android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="20.0dip"
android:cacheColorHint="@null"
android:listSelector="@drawable/shape_bg_listview"
android:background="@drawable/shape_bg_listview"
/>
代码:
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<String> list =new ArrayList<String>();
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<String> list;
AppAdapter(Context context,ArrayList<String> 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定义如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/name"
android:textSize="17.0sp"
android:textColor="@android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20.0dip"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
>
</TextView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20.0dip"
android:src="@drawable/arrow"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
>
</ImageView>
</RelativeLayout>
App列表之圆角ListView(续)
http://www.cnblogs.com/qianxudetianxia/archive/2011/12/11/2283794.html
圆角背景的ListView
更多文章、技术交流、商务合作、联系博主
微信扫码或搜索:z360901061
微信扫一扫加我为好友
QQ号联系: 360901061
您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。
【本文对您有帮助就好】元