ViewFlipper flipper;
// 터치 이벤트 발생 지점의 x좌표 저장
float xAtDown;
float xAtUp;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE); //타이틀바 숨김
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); //상태바 숨김
setContentView(R.layout.sig_guide);
flipper = (ViewFlipper)findViewById(R.id.viewFlipper);
flipper.setOnTouchListener(this);
}
// View.OnTouchListener의 abstract method
// flipper 터지 이벤트 리스너
public boolean onTouch(View v, MotionEvent event) {
Bitmap bitmap;
// 터치 이벤트가 일어난 뷰가 ViewFlipper가 아니면 return
if(v != flipper) return false;
if(event.getAction() == MotionEvent.ACTION_DOWN) {
xAtDown = event.getX(); // 터치 시작지점 x좌표 저장
}
else if(event.getAction() == MotionEvent.ACTION_UP){
xAtUp = event.getX(); // 터치 끝난지점 x좌표 저장
if( xAtUp < xAtDown ) {
// 왼쪽 방향 에니메이션 지정
flipper.setInAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_left_in));
flipper.setOutAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_left_out));
// 다음 view 보여줌
flipper.showNext();
}
else if (xAtUp > xAtDown){
// 오른쪽 방향 에니메이션 지정
flipper.setInAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_right_in));
flipper.setOutAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_right_out));
// 전 view 보여줌
flipper.showPrevious();
}
}
return true;
}
레이아웃
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ViewFlipper
android:id="@+id/viewFlipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="@+id/view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/guide_main"
/>
<ImageView
android:id="@+id/view2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/guide_1"
/>
<ImageView
android:id="@+id/view3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/guide_2"
/>
<ImageView
android:id="@+id/view4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/guide_3"
/>
<ImageView
android:id="@+id/view5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/guide_5"
/>
<ImageView
android:id="@+id/view6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/guide_6"
/>
<ImageView
android:id="@+id/view7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/guide_7"
android:onClick="GuideItemClick"
/>
</ViewFlipper>
</LinearLayout>
위처럼 코드를 작성하고 720x1230 이미지 8개를 사용하니 아웃오브메모리로 앱이 죽어버립니다.
recycle() 를 쓰면 된다지만 플립뷰에서 어떻게 써야 하는지 감이 오지 않아 질문을 드립니다..
조언 부타드리겠습니다..