I have a thumbnail gallery. I would like to impose a bitmap over every thumbnail image. The resultant image should be either a bitmap or a drawable. Hence the gallery now consists of these resultant images. When the user scrolls through the gallery, the resultant image will appear. I am using the following code
public class GalleryVideo extends Activity {
private Integer[] imgId = {R.drawable.followtheleader,
R.drawable.fruitsalad,
R.drawable.gettingstrong,
R.drawable.gulpgulp,
R.drawable.heythereshakyshaky,
R.drawable.its_a_wiggly_circus,
R.drawable.lettucesing,
R.drawable.monkey_dance,
R.drawable.quack_quack,
R.drawable.vegetable_soup,
R.drawable.walk};
public void onCreate(Bundle savedInstanceState) {
....................
selected_photo = (ImageView)findViewById(R.id.selected_photo);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
bitmap = BitmapFactory.decodeFile(photoPath, options);
selected_photo.setImageBitmap(bitmap);
gallery = (Gallery) findViewById(R.id.examplegallery);
gallery.setAdapter(new AddImgAdp(getApplicationContext()));
th_name = (ImageView)findViewById(R.id.th_name);
gallery.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id) {
galleryVideoCounter = position;
Intent myIntent = new Intent(getApplicationContext(), StartDance.class);
startActivity(myIntent);
}
});
....................
}
public class AddImgAdp extends BaseAdapter {
int GalItemBg;
private Context cont;
public AddImgAdp(Context c) {
cont = c;
TypedArray typArray = obtainStyledAttributes(R.styleable.GalleryTheme);
GalItemBg = typArray.getResourceId(R.styleable.GalleryTheme_android_galleryItemBackground, 0);
typArray.recycle();
}
public int getCount() {
return imgId.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
try {
if(position > 0)
{
audioPosCount = position;
}
if(audioPosCount == 0 && audioPosCount != audioPosCount1)
{
galleryAudioCounter++;
audioPosCount1 = audioPosCount;
}
if(audioPosCount > 0 && audioPosCount != -1 && audioPosCount != audioPosCount1)
{
galleryAudioCounter++;
audioPosCount = position;
audioPosCount1 = audioPosCount;
}
return position;
} catch (Exception e) {
}
}
public View getView(int position, View convertView, ViewGroup parent) {
audioPosCount = 0;
ImageView imgView = new ImageView(getApplicationContext());
imgView.setImageResource(imgId[position]);
imgView.setLayoutParams(new Gallery.LayoutParams(((int)(width / 1.45)), ((int)(height / 1.6))));
imgView.setScaleType(ImageView.ScaleType.FIT_XY);
return imgView;
}
}
}
I n开发者_Python百科eed a sample code for this feature.
精彩评论