1

私は Android 開発に不慣れで、ビューにグラフィック描画を実装しようとすると難しい問題に遭遇します。

私がやりたいのは、ビューにグラフを描くことです。View を ScrollView に配置し、View の onDraw メソッドをオーバーライドして、onDraw で描画を行います。最も重要なことは、チャートにスクロール機能が必要なことです。私がオーバーライドするビューの onDraw メソッドには、チャート内の座標計算と多くの必要な要素 (線、点、軸、ラベルなど) の描画が含まれます。ご想像のとおり、可視領域だけでなく、画面外も含めた全体のグラフを計算して描画します。問題は、ScrollView をスクロールするときに onDraw メソッドが何度も呼び出されるため、パフォーマンスの問題が発生し、スクロール ビューの実行が非常に遅くなることです。最初の呼び出し後に onDraw の呼び出しを防ぐ方法を見つけようとしていましたが、運が悪かったです。onDraw が呼び出されると、同じことを何度も計算する必要がありますが、これは必要ありません。

皆さん、何か答えはありますか?ありがとう。

4

1 に答える 1

0

mScrollX と mScrollY を使用して、キャンバスのどの可視部分を再描画する必要があるかを計算できます。

 /**
 * The offset, in pixels, by which the content of this view is scrolled
 * vertically.
 * {@hide}
 */
@ViewDebug.ExportedProperty
protected int mScrollY;

/**
 * The left padding in pixels, that is the distance in pixels between the
 * left edge of this view and the left edge of its content.
 * {@hide}
 */
@ViewDebug.ExportedProperty
protected int mPaddingLeft;
/**
 * The right padding in pixels, that is the distance in pixels between the
 * right edge of this view and the right edge of its content.
 * {@hide}
 */
@ViewDebug.ExportedProperty
protected int mPaddingRight;
/**
 * The top padding in pixels, that is the distance in pixels between the
 * top edge of this view and the top edge of its content.
 * {@hide}
 */
@ViewDebug.ExportedProperty
protected int mPaddingTop;
/**
 * The bottom padding in pixels, that is the distance in pixels between the
 * bottom edge of this view and the bottom edge of its content.
 * {@hide}
 */
@ViewDebug.ExportedProperty
protected int mPaddingBottom;
于 2010-12-31T09:30:36.307 に答える