zoukankan      html  css  js  c++  java
  • 3月19日学习日志

    今天学习了翻转视图的使用。

    activity代码为:

    public class MainActivity extends AppCompatActivity  {
    
        private Context mContext;
        private ViewFlipper vflp_help;
        private int[] resId = {R.mipmap.ic_help_view_1,R.mipmap.ic_help_view_2,
                R.mipmap.ic_help_view_3,R.mipmap.ic_help_view_4};
    
        private final static int MIN_MOVE = 200;   //最小距离
        private MyGestureListener mgListener;
        private GestureDetector mDetector;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            mContext = MainActivity.this;
            //实例化SimpleOnGestureListener与GestureDetector对象
            mgListener = new MyGestureListener();
            mDetector = new GestureDetector(this, mgListener);
            vflp_help = (ViewFlipper) findViewById(R.id.vflp_help);
            //动态导入添加子View
            for(int i = 0;i < resId.length;i++){
                vflp_help.addView(getImageView(resId[i]));
            }
    
        }
    
        //重写onTouchEvent触发MyGestureListener里的方法
        @Override
        public boolean onTouchEvent(MotionEvent event) {
            return mDetector.onTouchEvent(event);
        }
    
    
        //自定义一个GestureListener,这个是View类下的,别写错哦!!!
        private class MyGestureListener extends GestureDetector.SimpleOnGestureListener {
            @Override
            public boolean onFling(MotionEvent e1, MotionEvent e2, float v, float v1) {
                if(e1.getX() - e2.getX() > MIN_MOVE){
                    vflp_help.setInAnimation(mContext,R.anim.right_in);
                    vflp_help.setOutAnimation(mContext, R.anim.right_out);
                    vflp_help.showNext();
                }else if(e2.getX() - e1.getX() > MIN_MOVE){
                    vflp_help.setInAnimation(mContext,R.anim.left_in);
                    vflp_help.setOutAnimation(mContext, R.anim.left_out);
                    vflp_help.showPrevious();
                }
                return true;
            }
        }
    
        private ImageView getImageView(int resId){
            ImageView img = new ImageView(this);
            img.setBackgroundResource(resId);
            return img;
        }
    }
  • 相关阅读:
    002 下载文件
    001 okhttp3的POST使用
    000 okhttp3的Get使用
    008 webpack的其他使用方式
    007 webpack基本的用法
    three.js 3d三维网页代码加密的实现方法
    物联网开发技术栈
    9个顶级开发IoT项目的开源物联网平台
    hibernate缓存机制详细分析
    机器学习大牛最常用的5个回归损失函数,你知道几个?
  • 原文地址:https://www.cnblogs.com/20193925zxt/p/14883182.html
Copyright © 2011-2022 走看看