public class ImageVT extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Gallery g = (Gallery) findViewById(R.id.gallery);
g.setAdapter(new ImageAdapter(this));
g.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id) {
Toast.makeText(ImageVT.this, "" + position, Toast.LENGTH_SHORT).show();
}
});
}
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
private Integer[] mImageIds = {
R.drawable.a01,
R.drawable.a02,
R.drawable.a03,
R.drawable.a04,
R.drawable.a05,
R.drawable.a06,
R.drawable.a07,
R.drawable.a08,
R.drawable.a09,
R.drawable.a10,
R.drawable.a11,
R.drawable.a12
};
public ImageAdapter(Context c) {
mContext = c;
TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
mGalleryItemBackground = a.getResourceId(
R.styleable.Gallery1_android_galleryItemBackground, 0);
a.recycle();
}
public int getCount() {
return mImageIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
i.setImageResource(mImageIds[position]);
//i.setLayoutParams(new Gallery.LayoutParams(700, 809));
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
i.setBackgroundResource(mGalleryItemBackground);
return i;
}
}
}
'스마트폰 > 안드로이드' 카테고리의 다른 글
묵시적 intent 공부. (0) | 2011.05.13 |
---|---|
이미지뷰 두번째 공부. (0) | 2011.05.13 |
웹 소스 찍기 (0) | 2011.05.13 |
데이터 바인딩4 공부 (0) | 2011.05.13 |
데이터 바인딩3 공부 (0) | 2011.05.13 |