亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

正在回答

2 回答

講的無法運行

0 回復 有任何疑惑可以回復我~
//下拉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>


0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

拉不動怎么辦

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號