我嘗試了很多事情來處理我的問題,但它並不真正工作,而google也不能幫助我。 我有一個包含畫布的ImageView 。 畫布繪製圖形的一部分。 所以當用戶滾動( 水平) 時,畫布應該繪製圖形的另一部分。 例如:
畫布寬度為 200像素
畫布從x=0到x=200繪製圖形。
用戶滾動( 水平),他移動手指超過 100像素
畫布現在應該從x=100到x=300繪製圖形。
畫布應該按用戶滾動( 用於平滑滾動)的每個像素重繪這裡解決方案: 繪製整個圖形並將它的放入Scrollview中。 因為畫布/點陣圖太大,所以它提供了一個 OutOfMemoryError 。
我還需要做一些其他事情,所以我需要像上面描述的那樣做。
下面是代碼:
xml:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/graph"
android:background="@android:color/black"
android:name="de.touristenfahrerforum.MarcelMoiser.Fragments.SpeedGraph">
Java類:public class SpeedGraph extends ImageView
{
...
public SpeedGraph(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public SpeedGraph(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SpeedGraph(Context context) {
super(context);
}
public void setup( ArrayList locations, ScrollViewListener scrollViewListener )
{
...
Bitmap bitmap = Bitmap.createBitmap(speedCanvasWidth,speedCanvasHeight,Bitmap.Config.ARGB_8888);
canvas = new Canvas(bitmap);
this.setImageBitmap(bitmap);
...}
...
private void drawGraph(int start, int end, int color)
{
graphPaint.setColor(color);
long startTime = locations.get(start).getTime();
Path path = new Path();
path.moveTo((locations.get(start).getTime()-startTime)/10*V.LOGICAL_DENSITY, speedCanvasHeight-(int)(locations.get(start).getSpeed()*3.6*SIZE_FACTOR));
for( int it = start; it
{
Location location = locations.get(it);
path.lineTo((location.getTime()-startTime)/10*V.LOGICAL_DENSITY, speedCanvasHeight-(int)(location.getSpeed()*3.6*SIZE_FACTOR));
}
canvas.drawPath(path,graphPaint);
}
...
所以我想實現一些可以識別水平滾動手勢的東西,並給我一些像素,這些像素顯示用戶滾動的像素。
謝謝大家提前