zoukankan      html  css  js  c++  java
  • android ViewFlipper(翻转视图) 使用

    1、布局文件

    <RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.example.helloword.FlipperActivity" >
    
       <ViewFlipper
           android:id="@+id/flipper"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"></ViewFlipper>
    
    </RelativeLayout>

    2、drawable 图片

    3、Activity:

    package com.example.helloword;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.GestureDetector;
    import android.view.MotionEvent;
    import android.view.View;
    import android.view.animation.Animation;
    import android.view.animation.AnimationUtils;
    import android.widget.ImageView;
    import android.widget.ViewFlipper;
    
    public class FlipperActivity extends Activity implements View.OnClickListener, GestureDetector.OnGestureListener{
    
        final int distance = 50;
        
        private Animation[] animations = new Animation[4];
        
        private int[] images = new int[]{
                R.drawable.img0,R.drawable.img1,R.drawable.img2,R.drawable.img3,
                R.drawable.img4
        };
        
        private ViewFlipper flipper ;
        
        private GestureDetector detector;
        
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_flipper);
            
            detector = new GestureDetector(FlipperActivity.this,this);
            flipper = findViewById(R.id.flipper);
            
            for (int i = 0; i < images.length; i++) {
                ImageView img = new ImageView(this);
                img.setImageResource(images[i]);
                flipper.addView(img);
            }
            
            animations[0] = AnimationUtils.loadAnimation(this, R.anim.abc_slide_in_bottom);
            animations[1] = AnimationUtils.loadAnimation(this, R.anim.abc_slide_out_bottom);
            animations[2] = AnimationUtils.loadAnimation(this, R.anim.abc_slide_in_top);
            animations[3] = AnimationUtils.loadAnimation(this, R.anim.abc_slide_out_bottom);
        }
    
        @Override
        public void onPointerCaptureChanged(boolean hasCapture) {
            // TODO Auto-generated method stub
            
        }
    
        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            
        }
    
        @Override
        public boolean onDown(MotionEvent arg0) {
            // TODO Auto-generated method stub
            return false;
        }
    
        @Override
        public boolean onFling(MotionEvent arg0, MotionEvent arg1, float arg2,
                float arg3) {
            if(arg0.getY()-arg1.getY()>distance){
                flipper.setInAnimation(animations[2]);
                flipper.setOutAnimation(animations[1]);
                flipper.showPrevious();
                return true;
            }else if(arg1.getY()-arg0.getY()>distance){
                flipper.setInAnimation(animations[0]);
                flipper.setOutAnimation(animations[3]);
                flipper.showNext();
                return true;
            }
            
            return false;
        }
    
        @Override
        public void onLongPress(MotionEvent arg0) {
            // TODO Auto-generated method stub
            
        }
    
        @Override
        public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2,
                float arg3) {
            // TODO Auto-generated method stub
            return false;
        }
    
        @Override
        public void onShowPress(MotionEvent arg0) {
            // TODO Auto-generated method stub
            
        }
    
        @Override
        public boolean onSingleTapUp(MotionEvent arg0) {
            // TODO Auto-generated method stub
            return false;
        }
    
        @Override
        public boolean onTouchEvent(MotionEvent event) {
            // TODO Auto-generated method stub
            return detector.onTouchEvent(event);
        }
    
        
    
    }
  • 相关阅读:
    分布式服务调用链路追踪——方案选型
    分布式服务调用链路追踪——Skywalking
    JVM——jhat命令
    JVM——jmap命令
    JVM——jstack命令
    JVM——jstat命令
    JVM——jinfo命令
    针对input添加padding后宽度变化问题
    HTTPS实现原理
    selenium异常捕获
  • 原文地址:https://www.cnblogs.com/zoro-zero/p/11562322.html
Copyright © 2011-2022 走看看