Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test.tet;
- import android.content.Context;
- import android.content.res.TypedArray;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.BaseAdapter;
- import android.widget.Gallery;
- import android.widget.ImageView;
- public class ImageAdapter extends BaseAdapter {
- int mGalleryItemBackground;
- private Context mContext;
- private Integer[] mImageIds = {
- R.drawable.sample_1,
- R.drawable.sample_2,
- R.drawable.sample_3,
- R.drawable.sample_4,
- R.drawable.sample_5,
- R.drawable.sample_6,
- R.drawable.sample_7
- };
- public ImageAdapter(Context c) {
- mContext = c;
- TypedArray attr = mContext.obtainStyledAttributes(R.styleable.HelloGallery);
- mGalleryItemBackground = attr.getResourceId(
- R.styleable.HelloGallery_android_galleryItemBackground, 0);
- attr.recycle();
- }
- public int getCount() {
- return mImageIds.length;
- }
- public Object getItem(int position) {
- return position;
- }
- public long getItemId(int position) {
- return position;
- }
- //debug
- public void setLayoutParams(int x,int y){
- }
- public View getView(int position, View convertView, ViewGroup parent) {
- ImageView imageView = new ImageView(mContext);
- imageView.setImageResource(mImageIds[1]);
- imageView.setLayoutParams(new Gallery.LayoutParams(300, 300));
- imageView.setScaleType(ImageView.ScaleType.FIT_XY);
- imageView.setBackgroundResource(mGalleryItemBackground);
- return imageView;
- }
- }
Add Comment
Please, Sign In to add comment