当前位置:操作系统 > 安卓/Android >>

android学习笔记21--------------Android中RelativeLayout+ListView

效果图
\

public class ListViewActivity extends ListActivity
 {
     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState)
     {
         super.onCreate(savedInstanceState);
         // setContentView(R.layout.main); 
 
         SimpleAdapter adapter = new SimpleAdapter(this, getData(),
                 R.layout.main, new String[]
                 {"title","info","img"}, new int[]
                 { R.id.title, R.id.info, R.id.img });
         setListAdapter(adapter);
     }
 
     private List<Map<String, Object>> getData()
     {
         List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
         Map<String, Object> map = new HashMap<String, Object>();
         map.put("title", "G1");
         map.put("info", "google 1");
         map.put("img", R.drawable.icon);
         list.add(map);
         map = new HashMap<String, Object>();
         map.put("title", "G2");
         map.put("info", "google 2");
         map.put("img", R.drawable.icon);
         list.add(map);
         map = new HashMap<String, Object>();
         map.put("title", "G3");
         map.put("info", "google 3");
         map.put("img", R.drawable.icon);
         list.add(map);
         return list;
     }
 }
 public class ListViewActivity extends ListActivity
 {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState)
  {
   super.onCreate(savedInstanceState);
   // setContentView(R.layout.main);
 
  SimpleAdapter adapter = new SimpleAdapter(this, getData(),
     R.layout.main, new String[]
     {"title","info","img"}, new int[]
     { R.id.title, R.id.info, R.id.img });
   setListAdapter(adapter);
  }
 
 private List<Map<String, Object>> getData()
  {
   List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
   Map<String, Object> map = new HashMap<String, Object>();
   map.put("title", "G1");
   map.put("info", "google 1");
   map.put("img", R.drawable.icon);
   list.add(map);
   map = new HashMap<String, Object>();
   map.put("title", "G2");
   map.put("info", "google 2");
   map.put("img", R.drawable.icon);
   list.add(map);
   map = new HashMap<String, Object>();
   map.put("title", "G3");
   map.put("info", "google 3");
   map.put("img", R.drawable.icon);
   list.add(map);
   return list;
  }
 }
 [java]
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical" android:layout_width="fill_parent"
     android:layout_height="fill_parent">
 
     <RelativeLayout 
         android:orientation="vertical"
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content">
          
          <ImageView 
             android:id="@+id/img"         
             android:layout_width="wrap_content"       
             android:layout_height="wrap_content"         
             android:layout_margin="2px"/>
             
         <TextView 
             android:id="@+id/title" 
             android:layout_width="wrap_content"
             android:layout_height="wrap_content" 
             android:layout_toRightOf="@id/img"
             android:textColor="#FFFFFFFF"
             android:textSize="22px" />
             
         <TextView 
             android:id="@+id/info" 
             android:layout_toRightOf="@id/img"
             android:layout_alignBottom="@id/img"
      &nb

补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,