android listview顺序,android – 列表项(视图)顺序在ListView中快速滚动时快速地改变...

我是

android的新手,最后(不得不)在这里问一个问题,

让我们简单一点,我只想制作自己的TextView

(MyView扩展了View),

这是我的代码:

public class MyView extends View {

private Paint mPaint;

private String mText;

private Bitmap mBitmap1;

private Bitmap mBitmap2;

public MyView(Context context) {

super(context);

initView();

}

public MyView(Context context, AttributeSet attrs) {

super(context, attrs);

initView();

}

private final void initView() {

mPaint = new Paint();

}

public void setText(String text) {

mText = text;

}

@Override

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

int measuredWidth = measureWidth(widthMeasureSpec);

if (mBitmap1 == null) initBitmap1(measuredWidth);

int measuredHeight = measureHeight(heightMeasureSpec);

setMeasuredDimension(measuredWidth, measuredHeight);

}

private void initBitmap1(int measuredWidth) {

mBitmap1 = Bitmap.createBitmap(measuredWidth, Fonts.getHeight(), Bitmap.Config.ARGB_4444);

Canvas canvas = new Canvas(mBitmap1 );

canvas.drawText(mText, 0, 0, mPaint);

}

private void initBitmap2() {

mBitmap2 = Bitmap.createBitmap(30, Fonts.getHeight(), Bitmap.Config.ARGB_4444);

Canvas canvas = new Canvas(mBitmap2);

canvas.drawText(mText, 0, 0, mPaint);

}

private int measureWidth(int widthMeasureSpec) {

int measuredWidth = 0;

int specWidthMode = MeasureSpec.getMode(widthMeasureSpec);

int specWidthSize = MeasureSpec.getSize(widthMeasureSpec);

if (specWidthMode == MeasureSpec.EXACTLY) {

measuredWidth = specWidthSize;

} else {

measuredWidth = getWidth();

if (specWidthMode == MeasureSpec.AT_MOST) {

measuredWidth = Math.min(measuredWidth, specWidthSize);

}

}

return measuredWidth;

}

private int measureHeight(int heightMeasureSpec) {

int measuredHeight = 0;

int specHeightMode = MeasureSpec.getMode(heightMeasureSpec);

int specHeightSize = MeasureSpec.getSize(heightMeasureSpec);

if (specHeightMode == MeasureSpec.EXACTLY) {

measuredHeight = specHeightSize;

} else {

measuredHeight = 80;

if (specHeightMode == MeasureSpec.AT_MOST) {

measuredHeight = Math.min(measuredHeight, specHeightSize);

}

}

return measuredHeight;

}

@Override

protected void onDraw(Canvas canvas) {

super.onDraw(canvas);

canvas.drawBitmap(mBitmap1, getLeft(), 0, mPaint);

initBitmap2();

canvas.drawBitmap(mBitmap2, getLeft(), 30, mPaint);

}

}

在我的代码中,我填充了一些MyView(比方说20)

ListActivity

我的问题是为什么当我滚动时mBitmap1的顺序会随机变化

(快速上下)(如果我慢慢滚动,这个问题不会发生)..?

mBitmap2保留在那些应该是…

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值