課程
/移動開發
/Android
/自定義實現頂部粘性下拉刷新效果
就是圓那里下拉沒反應
2018-07-10
源自:自定義實現頂部粘性下拉刷新效果 2-2
正在回答
講的無法運行
//下拉View public?class?PullDownView?extends?View?{ ????private?float?mProgress; ????Paint?mCirclePaint; ????private?int?mCircleRadius?=?150; ????private?int?mCircleRadiuX,?mCircleRadiuY; ????//可拖動的高度 ????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); ????????//設置抗鋸齒 ????????paint.setAntiAlias(true); ????????//設置防抖 ????????paint.setDither(true); ????????//設置填充方式 ????????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; ????????} ????????//設置寬高 ????????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; ????} ????/** ?????*?設置拖動進度 ?????*?@param?progress ?????*/ ????public?void?setProgress(float?progress){ ????????Log.e("TAG",?"p"+progress); ????????mProgress?=?progress; ????????requestLayout(); ????} } //RelativeLayout下拉監聽 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>
舉報
構建一個可拉動的自定義View,自定義實現粘性下拉控件
1 回答下拉后回不去
3 回答動畫是怎么設置上的?
1 回答TouchpullView后面怎么個個函數
1 回答設置iHeight最小值 是怎么肥事
1 回答來這是釋放動畫的方法
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2018-11-04
講的無法運行
2018-07-20