android 游戏滚动画布,在 Imageview ( 使用画布) 中没有 ScrollView,分析并处理滚动手势_android_开发99编程知识库...

我嘗試了很多事情來處理我的問題,但它並不真正工作,而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);

}

...

所以我想實現一些可以識別水平滾動手勢的東西,並給我一些像素,這些像素顯示用戶滾動的像素。

謝謝大家提前

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值