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 stub
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
this.mContext = context;
}
@Override
protected 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();
}
}
自定义View 滚动条
最新推荐文章于 2024-07-04 17:02:14 发布