android 학습 노트 21 ---------- RelativeLayout + ListView

전재 출처 를 밝 혀 주 십시오:http://blog.csdn.net/yf210yf
효과 도
android学习笔记21--------------RelativeLayout+ListView_第1张图片
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;
	}
}
<?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"
			android:layout_width="wrap_content"
			android:layout_height="wrap_content" 
			android:textColor="#FFFFFFFF"
			android:textSize="13px" />
	</RelativeLayout>



</LinearLayout>

ListActivity 에 setListAdapter () 방법 이 있 습 니 다.// ListView 中某项被选中后的逻辑 
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id)
	{
		Log.v("MyListView4-click", (String) mData.get(position).get("title"));
	}



   

좋은 웹페이지 즐겨찾기