自定义View 滚动条

来源:互联网 发布:少女前线 知乎 编辑:程序博客网 时间:2024/05/16 17:30
package com.android.systemui.statusbar.phone;import android.content.Context;import android.util.AttributeSet;import android.util.Log;import android.view.View;import android.view.ViewGroup;import android.widget.LinearLayout;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import com.android.systemui.R;public class CustomScrollBarView extends View {private Paint mPaint;private int mCount;private int mIndex;private Context mContext;private int mOldIndex;public CustomScrollBarView(Context context, AttributeSet attrs) {super(context, attrs);// TODO Auto-generated constructor stubmPaint = new Paint(Paint.ANTI_ALIAS_FLAG);this.mContext = context;}@Overrideprotected void onDraw(Canvas canvas) {if (mCount == 0 || mIndex == 0) {return;}if (mIndex == mOldIndex) {// return;}Log.d("SSSSS", "count = " + mCount +", index = " + mIndex);mPaint.setColor(mContext.getResources().getColor(R.color.black_alpha_10));int height = getHeight() / mCount;int showHeight = height * mIndex;Log.d("SSSSS", "showHeight - height = " + (showHeight - height) + ",showHeight = " + showHeight +", height = " + height);canvas.drawRect(0, showHeight - height, getWidth(), showHeight, mPaint);mOldIndex = mIndex;super.onDraw(canvas);}public void invalidateLayout(int count, int index) {mCount = count;mIndex = index;invalidate();}}

0 0
原创粉丝点击