zoukankan      html  css  js  c++  java
  • 多种方式实现滑动p91--105

    1.layout方法

    2.offsetLeftAndRight()与offsetTopAndBottom()方法

    3.LayoutParams(前提是要有父布局,根据父布局的类型决定LayoutParams的类型),设置leftMargin和topMargin属性,当然也可以直接使用ViewGroup.MarginLayoutParams

    4.scrollTo和scrollBy,前者代表移动到最标点(x,y),后者表示移动的增量(dx,dy),但是这个移动的是view的content

    5.Scroller,这个可以实现平滑效果,不像srcoolTo和scrollBy那样突兀,实际上也是使用了scrollTo方法,通过重写computeScroll()方法进行重绘,最后stascroll方法即可

      

      scroller = new Scroller(context);
     /**
         * 重写这个方法是Scroller使用的核心,系统的draw()方法中调用改方法
         */
        @Override
        public void computeScroll() {
            super.computeScroll();
            /**
             * 下面可作为模板
             */
            //判断Scroller是否执行完毕
            if (scroller.computeScrollOffset()) {
                ((View) getParent()).scrollTo(scroller.getCurrX()//获得当前滑动坐标
                        , scroller.getCurrY());
                //通过重绘来不断调用computeScroll,computeScroll()不会自动调用,只能通过invalidate()方法
                //invalidate()-->draw()-->computeScroll()
                invalidate();
            }
        }

    6.属性动画

    7.ViewDragHelper,google在support库里面提供的DrawerLayout和SlidingPaneLayout两个布局来实现侧滑,里面就是使用的ViewDragHelper

  • 相关阅读:
    C++扬帆远航——4(百钱百鸡)
    C++扬帆远航——3(打印图形)
    C++扬帆远航——2
    web开发之Servlet 三
    web开发之Servlet 二
    web开发之Servlet 一
    迟来的2017年计划
    JSP 学习二
    JSP 学习一
    window7 32位安装Oracle11g
  • 原文地址:https://www.cnblogs.com/zzw1994/p/5661046.html
Copyright © 2011-2022 走看看