2011-05-25 64 views

回答

1

當然,剛剛創建與位圖在您的畫廊適配器返回一個ImageView的

public class MyActivity extends Activity { 

     final List<Bitmap> bitmaps = new ArrayList<Bitmap>(); 

     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     final Gallery galleryV = (Gallery) findViewById(R.id.gallery); 
     galleryV.setAdapter(new BaseAdapter() { 
      @Override 
      public int getCount() { 
      return bitmaps.size(); 
      } 
      @Override 
      public Object getItem(int position) { 
      return bitmaps.get(position); 
      } 
      @Override 
      public long getItemId(int position) { 
      return position; 
      } 
      @Override 
      public View getView(final int position, View convertView, final ViewGroup parent) { 
      if (convertView == null) { 
       convertView = new ImageView(MyActivity.this); 
      } 
      ((ImageView) convertView).setImageBitmap(bitmaps.get(position)); 
      return convertView; 
      } 
     }); 
     } 
    }