課程
/移動(dòng)開發(fā)
/Android
/自定義實(shí)現(xiàn)頂部粘性下拉刷新效果
就是圓那里下拉沒反應(yīng)
2018-07-10
源自:自定義實(shí)現(xiàn)頂部粘性下拉刷新效果 2-2
正在回答
講的無法運(yùn)行
//下拉View public?class?PullDownView?extends?View?{ ????private?float?mProgress; ????Paint?mCirclePaint; ????private?int?mCircleRadius?=?150; ????private?int?mCircleRadiuX,?mCircleRadiuY; ????//可拖動(dòng)的高度 ????private?int?mDragHeight?=?800; ????public?PullDownView(Context?context)?{ ????????super(context); ????????init(); ????} ????public?PullDownView(Context?context,?@Nullable?AttributeSet?attrs)?{ ????????super(context,?attrs); ????????init(); ????} ????public?PullDownView(Context?context,?@Nullable?AttributeSet?attrs,?int?defStyleAttr)?{ ????????super(context,?attrs,?defStyleAttr); ????????init(); ????} ????@RequiresApi(api?=?Build.VERSION_CODES.LOLLIPOP) ????public?PullDownView(Context?context,?@Nullable?AttributeSet?attrs,?int?defStyleAttr,?int?defStyleRes)?{ ????????super(context,?attrs,?defStyleAttr,?defStyleRes); ????} ????private?void?init()?{ ????????Paint?paint?=?new?Paint(Paint.ANTI_ALIAS_FLAG); ????????//設(shè)置抗鋸齒 ????????paint.setAntiAlias(true); ????????//設(shè)置防抖 ????????paint.setDither(true); ????????//設(shè)置填充方式 ????????paint.setStyle(Paint.Style.FILL); ????????paint.setColor(0xff000000); ????????mCirclePaint?=?paint; ????} ????@Override ????protected?void?onDraw(Canvas?canvas)?{ ????????super.onDraw(canvas); ????????canvas.drawCircle(mCircleRadiuX,?mCircleRadiuY,?mCircleRadius,?mCirclePaint); ????} ????@Override ????protected?void?onMeasure(int?widthMeasureSpec,?int?heightMeasureSpec)?{ //????????super.onMeasure(widthMeasureSpec,?heightMeasureSpec); ????????int?widthMode?=?MeasureSpec.getMode(widthMeasureSpec); ????????int?width?=?MeasureSpec.getSize(widthMeasureSpec); ????????int?heightMode?=?MeasureSpec.getMode(heightMeasureSpec); ????????int?height?=?MeasureSpec.getSize(heightMeasureSpec); ????????int?minWidth?=?2*mCircleRadius+getPaddingLeft()+getPaddingRight(); ????????int?minHeight?=?(int)?((mDragHeight*mProgress?+0.5f)+getPaddingTop()+getPaddingBottom()); ????????int?measureWidth,?measureHeight; ????????if?(widthMode?==?MeasureSpec.EXACTLY){ ????????????//確定的值 ????????????measureWidth?=?width; ????????}?else?if?(widthMode?==?MeasureSpec.AT_MOST){ ????????????//最多的值 ????????????measureWidth?=?Math.min(minWidth,?width); ????????}?else?{ ????????????measureWidth?=?minWidth; ????????} ????????if?(heightMode?==?MeasureSpec.EXACTLY){ ????????????//確定的值 ????????????measureHeight?=?height; ????????}?else?if?(heightMode?==?MeasureSpec.AT_MOST){ ????????????//最多的值 ????????????measureHeight?=?Math.min(minHeight,?height); ????????}?else?{ ????????????measureHeight?=?minHeight; ????????} ????????//設(shè)置寬高 ????????setMeasuredDimension(measureWidth,?measureHeight); ????} ????@Override ????protected?void?onSizeChanged(int?w,?int?h,?int?oldw,?int?oldh)?{ ????????super.onSizeChanged(w,?h,?oldw,?oldh); ????????mCircleRadiuX?=?getWidth()>>1; ????????mCircleRadiuY?=?getHeight()>>1; ????} ????/** ?????*?設(shè)置拖動(dòng)進(jìn)度 ?????*?@param?progress ?????*/ ????public?void?setProgress(float?progress){ ????????Log.e("TAG",?"p"+progress); ????????mProgress?=?progress; ????????requestLayout(); ????} } //RelativeLayout下拉監(jiān)聽 final?PullDownView?pullDownView?=?findViewById(R.id.pulldown); findViewById(R.id.activity_main).setOnTouchListener(new?View.OnTouchListener()?{ ????@Override ????public?boolean?onTouch(View?view,?MotionEvent?motionEvent)?{ ????????int?action?=?motionEvent.getAction(); ????????switch?(action){ ????????????case?MotionEvent.ACTION_DOWN: ????????????????mTouchMoveStartY?=?motionEvent.getY(); ????????????????return?true; ????????????case?MotionEvent.ACTION_MOVE: ????????????????float?y?=?motionEvent.getY(); ????????????????if?(y>=mTouchMoveStartY){ ????????????????????float?moveSize?=?y?-?mTouchMoveStartY; ????????????????????float?progress?=?moveSize>=?TOUCH_MOVE_MAX_Y??1:?moveSize/TOUCH_MOVE_MAX_Y; ????????????????????pullDownView.setProgress(progress); ????????????????} ????????????????return?true; ????????????case?MotionEvent.ACTION_UP: ????????????????break; ????????} ????????return?false; ????} }); //Xml <?xml?version="1.0"?encoding="utf-8"?> <RelativeLayout?xmlns:android="http://schemas.android.com/apk/res/android" ????xmlns:top="http://schemas.android.com/apk/res-auto" ????android:id="@+id/activity_main" ????android:layout_width="match_parent" ????android:layout_height="match_parent" ????android:background="#fff"> ????<com.summer.h5.View.PullDownView ????????android:id="@+id/pulldown" ????????android:layout_width="match_parent" ????????android:layout_height="wrap_content"/> </RelativeLayout>
舉報(bào)
構(gòu)建一個(gè)可拉動(dòng)的自定義View,自定義實(shí)現(xiàn)粘性下拉控件
1 回答下拉后回不去
3 回答動(dòng)畫是怎么設(shè)置上的?
1 回答TouchpullView后面怎么個(gè)個(gè)函數(shù)
1 回答設(shè)置iHeight最小值 是怎么肥事
1 回答來這是釋放動(dòng)畫的方法
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2018-11-04
講的無法運(yùn)行
2018-07-20