直接贴代码 和效果: strings.xml <?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">Hello World, GalleryActivity!</string> <string name="app_name">GalleryActivity</string> <string name="about">关于</string> <string name="close">关闭</string> <string name="ok">确定</string> </resources> main.xml <?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" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <Gallery android:id="@+id/myGallery" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="bottom" android:spacing="1dip"></Gallery> </LinearLayout> GalleryActivity.java package com.itxinke.www; import android.app.Activity; import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.ImageView.ScaleType; import android.app.AlertDialog; public class GalleryActivity extends Activity { /** Called when the activity is first created. */ private Gallery myGallery; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); myGallery = (Gallery)findViewById(R.id.myGallery); myGallery.setAdapter(new ImageAdapter(this)); } public class ImageAdapter extends BaseAdapter { private Context myContext; private int[]myImageIds = { android.R.drawable.btn_minus, android.R.drawable.btn_radio, android.R.drawable.ic_dialog_dialer, android.R.drawable.ic_dialog_email }; public ImageAdapter(Context context) { this.myContext = context; } @Override public int getCount() { // TODO Auto-generated method stub return this.myImageIds.length; } @Override public Object getItem(int position) { // TODO Auto-generated method stub return 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 ImageView i = new ImageView(this.myContext); i.setImageResource(this.myImageIds[position]); i.setScaleType(ScaleType.FIT_XY); i.setLayoutParams(new Gallery.LayoutParams(100, 100)); return i; } public float getScale(boolean focused,int offset) { return Math.max(0, 1.0f/(float)Math.pow(2, Math.abs(offset))); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // TODO Auto-generated method stub menu.add(0,0,0,R.string.about); menu.add(0,1,1,R.string.close); return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { // TODO Auto-generated method stub switch(item.getItemId()) { case 0: openOptionDialog(); break; case 1: finish(); } return super.onOptionsItemSelected(item); } public void openOptionDialog() { new AlertDialog.Builder(this).setTitle(R.string.app_name). setMessage(R.string.about).setPositiveButton(R.string.ok,new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }).show(); } }