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;
        }
    }
  • 相关阅读:
    asp.net发送邮件
    jquery+TreeView 级联 复选框 checkbox 级联
    100层楼,两个会坏的杯子,测从哪层开始坏【算法思想】
    flex中dragdrop不响应的原因
    flex 中urlrequest缓存问题
    程序员技术练级攻略
    consistent hashing
    入门教材
    烙饼啊烙饼{转自ITEO
    杂乱的工作记录
  • 原文地址:https://www.cnblogs.com/20193925zxt/p/14883182.html
Copyright © 2011-2022 走看看