Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 배열
- paint
- 어노테이션
- 메서드
- Spring
- AWT
- Android
- Eclips
- 이클립스
- JavaScript
- 예외처리
- HTML
- 전화걸기
- 기본
- 생성자
- layout
- Java
- 국제화
- JSP
- 오버로딩
- mybatis
- 안드로이드
- 메소드
- Menu
- 에러페이지
- Graphic
- 클래스
- OGNL
- struts2
- oracle
Archives
- Today
- Total
note
Gallery ImageView 본문
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Gallery android:id="@+id/gallery" android:layout_width="fill_parent" android:layout_height="fill_parent" android:spacing="5px" android:animationDuration="1500" /> <!-- android:animationDuration="1500" 1000분의 1초 이미지 속도(슬라이딩?) --> </LinearLayout>
package kr.android.gallery;
import android.app.Activity;
import android.os.Bundle;
import android.content.Context;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Toast;
import android.view.View;
import android.view.ViewGroup;
public class GalleryTest extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//이벤트 소스
Gallery g = (Gallery) findViewById(R.id.gallery);
//Gallery에 ImageAdapter2를 이용해서 데이터 바인딩
g.setAdapter(new ImageAdapter2(this));
//익명 내부 클래스 형식의 이벤트 처리
g.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v,
int position, long id) {
//공지 (알림 메세지)처리를 위해 Toast 객체 생성
//Toast = 단순 공지(알림)
Toast.makeText(GalleryTest.this, position + "번째 이미지",
Toast.LENGTH_SHORT).show();
}
});
}
}
//사용자 정의 Adapter 클래스
class ImageAdapter2 extends BaseAdapter{
//추상 클래스 (get시리즈 갖고있음)
private Context cxt;
//이미지 저장소
private int[] mImageIds ={
R.drawable.a,
R.drawable.b,
R.drawable.c,
R.drawable.d,
R.drawable.e,
R.drawable.f,
R.drawable.g,
R.drawable.h,
R.drawable.i,
};
//생성자
public ImageAdapter2(Context cxt){
this.cxt = cxt;
}
//아이템의 갯수
public int getCount(){
return mImageIds.length;
}
//전달되는 position에 해당하는 데이터 반환
public Object getItem(int position){
return mImageIds[position];
}
//전달되는 position반환(데이터 베이스 연동시 프라이머리키를 대입시켜서 사용)
public long getItemId(int position) {
return position;
}
//ImageView를 생성해서 Gallery에 데이터 바인딩하는 메소드
//전달되는 인자
//int position : position 정보
//View convertView : 데이터가 표시되는 객체
//ViewGroup parent : 사용중인 Gallery 객체
public View getView(int position, View convertView, ViewGroup parent){
ImageView imageView;
if(convertView == null){
imageView = new ImageView(cxt);
}else{
imageView = (ImageView)convertView;
}
imageView.setImageResource(mImageIds[position]);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setLayoutParams(new Gallery.LayoutParams(300,150));
return imageView;
}
}
'Android > 기본' 카테고리의 다른 글
Tab 탭 (0) | 2012.01.10 |
---|---|
Chrono 시간 , 날짜 처리 (0) | 2012.01.10 |
AutoComplete 자동완성기능 (0) | 2012.01.10 |
그리드 Grid (0) | 2012.01.09 |
스핀 컨트롤 Spinner (0) | 2012.01.09 |