準備一個箭頭的.png 檔
main.java:
public class ListViewCorneredBgActivity 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. 台北 (Taipei)");
list.add("2. 台中 (Taichung)");
list.add("3. 台南 (Tainan)");
list.add("4. 基隆 (Keelung)");
list.add("5. 台東 (Taitung)");
list.add("6. 高雄 (Kaohsiung)");
mListView = (ListView)findViewById(R.id.list);
mListView.setAdapter(new AppAdapter(this,list));
}
class AppAdapter extends BaseAdapter implements ListAdapter{
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;
}
}
}
*********************************************************
res/layout/main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<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"
/>
</LinearLayout>
res/layout/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/arrowright1"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
>
</ImageView>
</RelativeLayout>
***********************
res/drawable/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>
參考網站:http://www.cnblogs.com/shanzei/archive/2012/03/24/2415887.html