제 문제를 처리하기 위해 많은 노력을했지만 실제로 작동하지 않았고 Google도 나를 도울 수 없었습니다. Canvas가 포함 된 ImageView가 있습니다. 캔버스는 그래프의 일부를 그립니다. 따라서 사용자가 (가로로) 스크롤 할 때 캔버스는 그래프의 다른 부분을 그려야합니다. 예를 들어ScrollView없이 이미지 뷰 (캔버스 포함)에서 스크롤 제스처를 분석하고 처리합니다.
는캔버스 폭은 캔버스에서 X = 0의 그래프를 그리는 200 픽셀
이고 X = 200
사용자가 스크롤을 (수평), 그는 100 픽셀
통해 자신의 손가락을 움직이는 캔버스 이제 X = 100 내지 그래프를 그린다 X = 300
캔버스는 모든 픽셀에 의해 묘화해야이 솔루션은 작동하지 않았 (부드러운 스크롤) 사용자가 스크롤 : WH 그리기 ole 그래프를 스크롤하여 Scrollview에 넣습니다. 캔버스/비트 맵이 너무 크기 때문에 OutOfMemoryError를 전달합니다.
또한 다른 작업을 수행해야하므로 위에서 설명한 것처럼이 작업을 수행해야합니다.
XML :
<de.touristenfahrerforum.Marcel.Fragments.SpeedGraph
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">
</de.touristenfahrerforum.Marcel.Fragments.SpeedGraph>
자바 클래스 : 여기
는 코드입니다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<Location> 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 < end; 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);
}
...
그래서 수평 스크롤 제스처를 인식하고 나에게의 수를 제공합니다 뭔가를 구현하고 싶습니다 사용자가 스크롤 한 픽셀을 나타내는 픽셀
사전