先上图:
哈哈 代驾和健康,加上家政 这吉祥三宝都是易盟公司的应用 请支持 。。。
说明设置界面是一般应用比不可少的组成,其布局一般使用圆角listview ,圆角的方法我也是从网上找的
http://blog.csdn.net/tt5267621/article/details/6987174
程序员都懒,你懂的.
1.先看布局 main_more.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:background="@color/white"
- android:orientation="vertical" >
- <LinearLayout
- android:id="@+id/linearLayout1"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- android:paddingBottom="5dp"
- android:paddingLeft="25dp"
- android:paddingTop="15dp" >
- <TextView
- android:id="@+id/menu_1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/setting"
- android:textColor="@color/gray" />
- </LinearLayout>
- <com.corner.test.CornerListView
- android:id="@+id/list1"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_marginLeft="15dp"
- android:layout_marginRight="15dp"
- android:background="@drawable/shape_bg_listview"
- android:cacheColorHint="@null"/>
- <LinearLayout
- android:id="@+id/linearLayout2"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- android:paddingBottom="5dp"
- android:paddingLeft="25dp"
- android:paddingTop="15dp" >
- <TextView
- android:id="@+id/menu_2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/setting"
- android:textColor="@color/gray" />
- </LinearLayout>
- <com.corner.test.CornerListView
- android:id="@+id/list2"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_marginLeft="15dp"
- android:layout_marginRight="15dp"
- android:background="@drawable/shape_bg_listview"
- android:cacheColorHint="@null"/>
- </LinearLayout>
2.再看代码:
- package com.corner.test;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.AdapterView;
- import android.widget.AdapterView.OnItemClickListener;
- import android.widget.SimpleAdapter;
- /* Android实现圆角ListView示例*/
- public class RoundCornerActivity extends Activity {
- private CornerListView cornerListView1 = null;
- private CornerListView cornerListView2 = null;
- ArrayList<HashMap<String, String>> map_list1 = null;
- private List<Map<String, Object>> map_list2 = null;
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main_more);
- cornerListView1 = (CornerListView)findViewById(R.id.list1);
- cornerListView2 = (CornerListView)findViewById(R.id.list2);
- getDataSource1();
- getDataSource2();
- SimpleAdapter adapter1 = new SimpleAdapter(getApplicationContext(), map_list1,R.layout.simple_list_item_1,
- new String[] { "item" },new int[] { R.id.item_title });
- cornerListView1.setAdapter(adapter1);
- cornerListView1.setOnItemClickListener(new OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
- long arg3) {
- if (arg2 == 0) {
- System.out.println("0");
- }else if(arg2 == 1){
- System.out.println("1");
- }
- else if(arg2 == 2){
- System.out.println("2");
- }
- }
- });
- SimpleAdapter adapter2 = new SimpleAdapter(getApplicationContext(), map_list2, R.layout.simple_list_item_2,
- new String[]{"text","img"}, new int[]{R.id.setting_list_item_text,R.id.setting_list_item_arrow});
- cornerListView2.setAdapter(adapter2);
- cornerListView2.setOnItemClickListener(new OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
- long arg3) {
- if (arg2 == 0) {
- System.out.println("3");
- }else if(arg2 == 1){
- System.out.println("4");
- }
- }
- });
- // cornerListView2.setOnItemClickListener(new OnItemListSelectedListener());
- }
- public ArrayList<HashMap<String, String>> getDataSource1() {
- map_list1 = new ArrayList<HashMap<String, String>>();
- HashMap<String, String> map1 = new HashMap<String, String>();
- HashMap<String, String> map2 = new HashMap<String, String>();
- HashMap<String, String> map3 = new HashMap<String, String>();
- map1.put("item", "设置1");
- map2.put("item", "设置2");
- map3.put("item", "设置3");
- map_list1.add(map1);
- map_list1.add(map2);
- map_list1.add(map3);
- return map_list1;
- }
- private List<Map<String, Object>> getDataSource2() {
- map_list2 = new ArrayList<Map<String, Object>>();
- Map<String, Object> map = new HashMap<String, Object>();
- map.put("text", "代驾宝");
- map.put("img", R.drawable.icon);
- map_list2.add(map);
- map = new HashMap<String, Object>();
- map.put("text", "健康宝");
- map.put("img", R.drawable.icon);
- map_list2.add(map);
- return map_list2;
- }
- }
- //
- // class OnItemListSelectedListener implements OnItemClickListener {
- //
- // @Override
- // public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
- // long arg3) {
- // if (arg2 == 0) {
- // System.out.println("0");
- // }else{
- // System.out.println("1");
- // }
- // }
这里面巧妙的使用了两个list完成了 整个布局,然后使用控件分别获得list的点击id ,加入监听。
下载地址 :http://www.kuaipan.cn/file/id_28743136620604773.htm