First of all add all the images in drawable no metter how big it is.
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
public class MainActivity extends Activity {
ImageView image1;
Gallery gallery;
private Runnable r;
private static int i = 0;
int[] image_array = { R.drawable.i_pad0000, R.drawable.i_pad0001,
R.drawable.i_pad0002, R.drawable.i_pad0003, R.drawable.i_pad0004,
R.drawable.i_pad0005, R.drawable.i_pad0006, R.drawable.i_pad0007,
R.drawable.i_pad0008, R.drawable.i_pad0009, R.drawable.i_pad0010,
R.drawable.i_pad0011, R.drawable.i_pad0012, R.drawable.i_pad0013,
R.drawable.i_pad0014, R.drawable.i_pad0015, R.drawable.i_pad0016,
R.drawable.i_pad0017, R.drawable.i_pad0018, R.drawable.i_pad0019,
R.drawable.i_pad0020, R.drawable.i_pad0021, R.drawable.i_pad0022,
R.drawable.i_pad0023, R.drawable.i_pad0024, R.drawable.i_pad0025,
R.drawable.i_pad0027, R.drawable.i_pad0028, R.drawable.i_pad0029,
R.drawable.i_pad0030, R.drawable.i_pad0031, R.drawable.i_pad0032,
R.drawable.i_pad0033, R.drawable.i_pad0034, R.drawable.i_pad0035,
R.drawable.i_pad0036, R.drawable.i_pad0037, R.drawable.i_pad0038,
R.drawable.i_pad0039, R.drawable.i_pad0040, R.drawable.i_pad0041,
R.drawable.i_pad0042, R.drawable.i_pad0043, R.drawable.i_pad0044,
R.drawable.i_pad0045, R.drawable.i_pad0046, R.drawable.i_pad0047,
R.drawable.i_pad0048, R.drawable.i_pad0049, R.drawable.i_pad0050,
R.drawable.i_pad0051, R.drawable.i_pad0052, R.drawable.i_pad0053,
R.drawable.i_pad0054, R.drawable.i_pad0055, R.drawable.i_pad0056,
R.drawable.i_pad0057, R.drawable.ipad0058, R.drawable.i_pad0059,
R.drawable.i_pad0060, R.drawable.i_pad0061, R.drawable.i_pad0062,
R.drawable.i_pad0063, R.drawable.i_pad0064, R.drawable.i_pad0065,
R.drawable.i_pad0066, R.drawable.i_pad0067, R.drawable.i_pad0068,
R.drawable.i_pad0069, R.drawable.i_pad0070, R.drawable.i_pad0071,
R.drawable.i_pad0072, R.drawable.i pad0073, R.drawable.i_pad0074};
int[] verse_titles_hindi = { R.drawable.img_1,
R.drawable.img_2, R.drawable.img_3,
R.drawable.img_4, R.drawable.img_5,
R.drawable.img_6, R.drawable.v_7,
R.drawable.img_8, R.drawable.img_9,
R.drawable.img_10, R.drawable.img_11,
R.drawable.img_12, R.drawable.img_13,
R.drawable.img_14, R.drawable.img_15,
R.drawable.img_16, R.drawable.img_17,
R.drawable.img_18, R.drawable.img_19,
R.drawable.img_20, R.drawable.img_21,
R.drawable.img_22, R.drawable.img_23,
R.drawable.img_24, R.drawable.img_25,
R.drawable.img_26, R.drawable.img_27,
R.drawable.img_28, R.drawable.img_29,
R.drawable.img_30, R.drawable.img_31,
R.drawable.img_32, R.drawable.img_33,
R.drawable.img_34, R.drawable.img_35,
R.drawable.img_36, R.drawable.img_37,
R.drawable.img_38, R.drawable.img_39,
R.drawable.img_40, R.drawable.img_41,
R.drawable.img_42, R.drawable.img_43 };
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image1 = (ImageView) findViewById(R.id.image);
gallery = (Gallery) findViewById(R.id.versesIndex);
gallery.setAdapter(new ImageAdapter(this, verse_titles_hindi));
r = new Runnable() {
public void run() {
image1.setImageResource(image_array[i]);
System.gc();
i++;
image1.postDelayed(r, 25);
if (i >= image_array.length) {
Log.i("log_tag", "" + i);
i = 0;
// image1.removeCallbacks(r);
}
}
};
image1.postDelayed(r, 25);
}
private class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
private int[] verse_title;
public ImageAdapter(Context c, int[] verse_title) {
// TODO Auto-generated constructor stub
this.verse_title = verse_title;
this.mContext = c;
TypedArray a = obtainStyledAttributes(R.styleable.Theme);
mGalleryItemBackground = a.getResourceId(
R.styleable.Theme_android_galleryItemBackground, 0);
a.recycle();
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return verse_title.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;
}
@SuppressWarnings("deprecation")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ImageView i = new ImageView(mContext);
i.setImageResource(verse_title[position]);
i.setLayoutParams(new Gallery.LayoutParams(353, 159));
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setBackgroundResource(mGalleryItemBackground);
return i;
}
}
}
This would be run with the gallery as well as multiple image in one image view.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.