我有一个 android 应用程序,其布局包含一个 Listview,它被充气
LayoutInflater inflater = getLayoutInflater();
row = inflater.inflate(R.layout.disc_row, parent, false);
“R.layout.disc_row”包含一个绘制画布的 SurfaceView。所以 ListView 中的每一行都包含一个 Canvas。滚动列表时,画布停留在其位置,而行的其他元素正在滚动。我认为这是设备的不良行为。在单击 ListItem 之前,同一个应用程序不会在模拟器上绘制任何内容。
有没有更好的在 ListViews 内绘制的策略(没有位图,只有一些线条)可能使用 Paint?模拟器系统它在活动中做了太多的工作。
提前致谢
附加类
public class DrawDiscInListView extends SurfaceView implements
SurfaceHolder.Callback {
private static final String TAG = "DISCONT SurfaceView";
public DrawDiscInListView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
tryDrawing(holder);
}
@Override
public void surfaceChanged(SurfaceHolder holder, int frmt, int w, int h) {
tryDrawing(holder);
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
private void tryDrawing(SurfaceHolder holder) {
Log.i(TAG, "Trying to draw...");
Canvas canvas = holder.lockCanvas();
if (canvas == null) {
Log.e(TAG, "Cannot draw onto the canvas as it's null");
} else {
drawMyStuff(canvas);
holder.unlockCanvasAndPost(canvas);
}
}
private void drawMyStuff(final Canvas canvas) {
Random random = new Random();
Log.i(TAG, "Drawing...");
canvas.drawRGB(255, 128, 128);
}
}