갤러리에서 여러장의 이미지를 보여주는데 이것저것 변경하고 싶은게 많이 있습니다.
우선 DB는 사용하지 않고
어댑터에서 배열로 이미지를 생성하여 getView에서 ImageView를 생성하여 Gallery 로 넘기고 있습니다.
우선 화면에 보여지는수가
7개 정보만 보여졌으면 합니다.
-----------------------------------------------------------------------------------------------
| | | | | | | |
| 0 | 1 | 2 | 3 | 4 | 5 | 6 |
------------------------------------------------------------------------------------------------
0 : 작고 많이 투명하게
1 : 2보다 더 작고 더 투명하게
2 : 3보다 작고 투명하게
3 : 기준
4 : 3보다 작고 투명하게
5 : 4보다 더 작고 더 투명하게
6 : 5보다 더 작고 더 투명하게
이렇게 보여지게 하고 싶습니다.
public class TestFActivity 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.setSelection(4, true); // 4번갤러리가 중심
}
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
private Integer[] mImageIds = {
R.drawable.cyca,
R.drawable.hyoyun,
R.drawable.pany,
R.drawable.suny,
R.drawable.suyoung,
R.drawable.tang,
R.drawable.ury,
R.drawable.yuna,
R.drawable.suhyun
};
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(120, 120));
//i.setAlpha(50);
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setBackgroundResource(mGalleryItemBackground);
return i;
}
}
}
getView 에서
i.setLayoutParams(new Gallery.LayoutParams(120, 120)) 식으로 주면 전체가 크기가 일정하게 나와서;
onCreate에서는
g.setUnselectedAlpha(0.60f); 주면 선택되어진 것은 잘 나오고 나머지가 모두 알파값이 일정해서;;
하나하나 바꾸는 방법을 알고 싶습니다.
초보여서 하나하나 쉽게 가르켜 주시면 감사합니다.
아 그리고 공지는 읽었어요;