<?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" >
<ViewFlipper
android:id="@+id/details"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/jessica" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/yuna" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/taeyeon" />
</ViewFlipper>
<!-- android:orientation을 안쓰면 기본적으로 horizontal -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<Button android:id="@+id/flip_pre"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="페이지 이전"
/>
<Button android:id="@+id/flip_me"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="다음 페이지"
/>
</LinearLayout>
</LinearLayout>
package com.commonsware.android.flipper1;
//플리퍼 Flipper 화면을 동적으로 구현하고 싶을때 사용
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ViewFlipper;
import android.view.View;
public class FilipperDemo extends Activity implements View.OnClickListener{
ViewFlipper flipper;
Button btnPre, btnNext;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
flipper=(ViewFlipper)findViewById(R.id.details);
btnPre = (Button)findViewById(R.id.flip_pre);
btnNext= (Button)findViewById(R.id.flip_me);
//이벤트 소스와 이벤트 리스너가 구현된 객체 연결
btnPre.setOnClickListener(this);
btnNext.setOnClickListener(this);
}
//이벤트 핸들러
public void onClick(View view) {
if(view.getId()==R.id.flip_me){
flipper.showNext();
}else{
flipper.showPrevious();
}
}
}