How to add image Bitmap in the Gallery component?
Is th开发者_如何学编程ere any way to insert a bitmap image in the gallery component?
Sure, just create and return an ImageView with your bitmap in your gallery adapter
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;
}
});
}
}
精彩评论