亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

android 可滑動的View

發布時間:2020-07-17 09:13:17 來源:網絡 閱讀:958 作者:王宇斌 欄目:移動開發

   效果圖如下:

android 可滑動的View


方法一(實現原理,主要依靠移動動畫<TranslateAnimation>),主要代碼如下:


private OnTouchListener gonggaoOnTouch() {
        return new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN: {
                    break;
                }
                case MotionEvent.ACTION_UP: {
                    if (mAdsV.getTop() == mSlipRl.getTop() && moveY < 0) {
                        topTag();
                    } else if (moveY < -200) {
                        topTag();
                    } else {
                        nextTag();
                    }
                    break;
                }
                }
                gestureDetector.onTouchEvent(event);
                return true;
            }
            private void topTag() {
                animBuilder.setDurationMillis(400).setFromYValue(formY)
                        .setToYValue(mAdsV.getTop() - mSlipRl.getTop());
                bgMoveAnim = animBuilder.build();
                bgMoveAnim.setAnimationListener(new AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {
                        // TODO Auto-generated method stub
                    }
                    @Override
                    public void onAnimationRepeat(Animation animation) {
                        // TODO Auto-generated method stub
                    }
                    @Override
                    public void onAnimationEnd(Animation animation) {
                        // TODO Auto-generated method stub
                        mSlipRl.clearAnimation();
                        setLayout(mSlipRl, 0, mAdsV.getTop(), 0);
                        mSlipRl.invalidate();
                    }
                });
                mSlipRl.startAnimation(bgMoveAnim);
            }
            private void nextTag() {
                animBuilder.setDurationMillis(400).setFromYValue(formY)
                        .setToYValue(mAdsV.getBottom() - mSlipRl.getTop());
                bgMoveAnim = animBuilder.build();
                bgMoveAnim.setAnimationListener(new AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {
                        // TODO Auto-generated method stub
                    }
                    @Override
                    public void onAnimationRepeat(Animation animation) {
                        // TODO Auto-generated method stub
                    }
                    @Override
                    public void onAnimationEnd(Animation animation) {
                        // TODO Auto-generated method stub
                        mSlipRl.clearAnimation();
                        setLayout(mSlipRl, 0, mAdsV.getBottom(), 0);
                        mSlipRl.invalidate();
                    }
                });
                mSlipRl.startAnimation(bgMoveAnim);
            }
        };
    }


方法二,主要代碼如下:


@Override
    public boolean dispatchTouchEvent(MotionEvent event) {
        // TODO Auto-generated method stub
        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            lastY = event.getY();
            if(null==mLocationSlip||null==mSlipDown||null==mSlipMove){
                mLocationSlip = this.findViewById(R.id.location_slip);
                mSlipDown = this.findViewById(R.id.down_slip);
                mSlipMove = this.findViewById(R.id.move_slip);
            }
            top = mSlipMove.getTop();
            bottom = mSlipDown.getBottom();
            if (top <= lastY && lastY <= (bottom + top)) {
                isMove = true;
                return true;
            }
        case MotionEvent.ACTION_MOVE:
            if (isMove) {
                float newY = event.getY();
                int ay = (int) ((lastY - newY) * 0.5);
                lastY = newY;
                mSlipMove.offsetTopAndBottom(-ay);
            }
            break;
        case MotionEvent.ACTION_UP:
            if (isMove) {
                isMove = false;
                top = mSlipMove.getTop();
                System.out.println(top + "====" + bottom + "==="+ mLocationSlip.getBottom()*2/3);
                if(!location&&top<(mLocationSlip.getBottom()*2/3)){
                    setLayout(mSlipMove, 0, 0, 0);
                    location=true;
                }else if(location&&top>(mLocationSlip.getBottom()*1/3)){
                    setLayout(mSlipMove, 0, mLocationSlip.getBottom(), 0);
                    location=false;
                }else if(!location){
                    setLayout(mSlipMove, 0, mLocationSlip.getBottom(), 0);
                }else{
                    setLayout(mSlipMove, 0, 0, 0);
                }
            }
            break;
        }
        return super.dispatchTouchEvent(event);
    }



主要知識點,就是重新設置了View的位置,android 3.0之后View可以同setTop(),setLeft()等一系列方法直接設置位置方便了開發。3.0之前位置變化設置方法:


/**
     * 給view重置位置
     * @param view
     * @param x
     * @param y
     * @param b
     */
    public void setLayout(View view, int x, int y, int b) {
        MarginLayoutParams margin = new MarginLayoutParams(
                view.getLayoutParams());
        margin.setMargins(x, y, 0, b);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
                margin);
        view.setLayoutParams(layoutParams);
    }


文章涉及知識點不多,相信一看就懂。如有問題,留言


下載移步:可滑動的View




向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

盐城市| 麦盖提县| 邢台市| 治县。| 巨野县| 清流县| 凌海市| 思茅市| 安庆市| 威宁| 巨野县| 高雄县| 巴东县| 瑞丽市| 巴林右旗| 巩义市| 凤阳县| 贞丰县| 苏尼特左旗| 观塘区| 澜沧| 梅河口市| 涡阳县| 辽阳县| 屏东市| 玛纳斯县| 通江县| 驻马店市| 余江县| 大兴区| 类乌齐县| 涟源市| 新宾| 蒙阴县| 虹口区| 丰原市| 汉寿县| 黔东| 襄城县| 收藏| 安吉县|