package com.example.helloandroid;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ViewFlipper;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
Button btnPrev,btnNext;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle("뷰플리퍼를 이용한 자동 사진보기 앱");
final ViewFlipper vf;
btnPrev=(Button)findViewById(R.id.btnPrev);
btnNext=(Button)findViewById(R.id.btnNext);
vf=(ViewFlipper)findViewById(R.id.viewFil1);
ImageView a1=(ImageView)findViewById(R.id.chinhan);
ImageView a2=(ImageView)findViewById(R.id.chiwawa);
ImageView a3=(ImageView)findViewById(R.id.mamang);
//사진 보기가 눌렸다면, 100단위로 flip함
btnPrev.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
vf.setFlipInterval(1000); //1000밀리초(1초)간격으로 flip을 set(넘김)
vf.startFlipping(); //위의 1밀리초를 인터버로, 지나면 넘김
}
});
btnNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
vf.stopFlipping();
}
});
}
}
///////////////
<?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:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/btnPrev"
android:text="사진보기 시작"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/btnNext"
android:text="사진보기 정지"/>
</LinearLayout>
<ViewFlipper
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/viewFil1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/chinhan"
android:id="@+id/chinhan"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/chiwawa"
android:id="@+id/chiwawa"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/mamang"
android:id="@+id/mamang"/>
</ViewFlipper>
</LinearLayout>
'애니리뷰' 카테고리의 다른 글
액션바를 자바코드만으로 구현 (0) | 2020.08.13 |
---|---|
직풀 6-3) (0) | 2020.08.13 |
안드 6장. 예제 및 실습 (2) | 2020.08.12 |
자료구조] string 내에서 지정된 문자열 검색 (4) | 2020.06.30 |
자료구조] 크루스칼 그린 다음, 전부 잘 연결 되었는지 확인하는 함수 (2) | 2020.06.25 |