IT/Android

android - ViewFlipper

노마드오브 2018. 9. 17. 21:30

파일명 : activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/btnPrev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=" 이전화면 " />

<Button
android:id="@+id/btnNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=" 다음화면 " />
</LinearLayout>
<ViewFlipper
android:id="@+id/viewFlipper1"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff0000" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="sadfasdfs"/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00ff00" >
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="성별"/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0000ff" >
</LinearLayout>
</ViewFlipper>
</LinearLayout>


파일명 : MainActivity.java

package com.example.it.myapplication6_16;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ViewFlipper;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Button btnPrev, btnNext;
final ViewFlipper vFlipper;

btnPrev = (Button) findViewById(R.id.btnPrev);
btnNext = (Button) findViewById(R.id.btnNext);
vFlipper = (ViewFlipper) findViewById(R.id.viewFlipper1);

vFlipper.setFlipInterval(1000);

btnPrev.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//vFlipper.showPrevious(); // 앞 화면으로 이동
vFlipper.startFlipping(); // 순차적으로 자동 페이지 전환
}
}
);

btnNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//vFlipper.showNext(); // 뒤 화면으로 이동
vFlipper.stopFlipping(); // 자동페이지 전환 멈추기
}
}
);
}
}