我有一個繪圖視圖和一個帶有元素的滾動視圖。問題是,我只能水平繪製線條,因爲當我嘗試垂直繪製線條時,由於ScrollView,視圖會向下滾動。如何防止滾屏同時在滾動視圖內繪製
當我刪除ScrollView時,垂直線也可以繪製,但我需要ScrollView才能顯示所有元素。
我試圖改變ScrollView中的overScrollMode
,但這不幫助。
如何防止向下滾動視圖,而我在繪製視圖中繪製?
下面是XML文件的相應部分:
滾動型 的xmlns:安卓= 「http://schemas.android.com/apk/res/android」 機器人:overScrollMode = 「從不」 機器人:ID = 「@ + ID/openproctScrollview」 機器人:layout_width = 「FILL_PARENT」 機器人:layout_height = 「match_parent」 機器人:layout_weight = 「1」 機器人:背景= 「#FFFFFF」 機器人:fillViewport =」 true「>
<FrameLayout
android:id="@+id/drawingLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.unitnode.Drawing
android:id="@+id/drawingView"
android:overScrollMode="ifContentScrolls"
android:layout_width="match_parent"
android:layout_height="match_parent" />
對不起這裏的繪畫班:
公共類圖紙擴展視圖{ 私人路徑的mpath; 私人畫布畫布; 私人畫圖mPaint; private Paint mBitmapPaint; 私人位圖mBitmap; private BlurMaskFilter mBlur; 私人MaskFilter mEmboss;
private float mX, mY;
private static final float TOUCH_TOLERANCE = 4;
public static String strichFarbeHex;
public Drawing(Context context, AttributeSet attrs) {
super(context, attrs);
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setDither(true);
mPaint.setStrokeWidth(12);
mPaint.setStyle(Paint.Style.STROKE);
mPath = new Path();
mBitmapPaint = new Paint(Paint.DITHER_FLAG);
this.setDrawingCacheEnabled(true);
mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 }, 0.4f, 6, 3.5f);
mBlur = new BlurMaskFilter(8, BlurMaskFilter.Blur.NORMAL);
this.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
float x = event.getX();
float y = event.getY();
Log.d("onTouch", "onTouch");
Log.d("x", String.valueOf(x));
Log.d("y", String.valueOf(y));
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
Log.d("a", "down");
Log.d("hier", "hier1");
touch_start(x, y);
invalidate();
break;
case MotionEvent.ACTION_MOVE:
Log.d("onTouch", "onTouch2");
touch_move(x, y);
invalidate();
break;
case MotionEvent.ACTION_UP:
Log.d("onTouch", "onTouch3");
touch_up();
invalidate();
break;
}
return true;
}
});
}
// mBlur = new BlurMaskFilter(8, BlurMaskFilter.Blur.NORMAL);
private void touch_start(float x, float y) {
// mPath.reset();
mPath.moveTo(x, y);
mX = x;
mY = y;
}
private void touch_move(float x, float y) {
float dx = Math.abs(x - mX);
float dy = Math.abs(y - mY);
if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2);
mX = x;
mY = y;
}
}
private void touch_up() {
mPath.lineTo(mX, mY);
// commit the path to our offscreen
canvas.drawPath(mPath, mPaint);
// kill this so we don't double draw
// mPaint.setXfermode(new PorterDuffXfermode(Mode.SCREEN));
// mPaint.setMaskFilter(null);
// mPath.reset();
}
@Override
public void onDraw(Canvas c) {
Log.d("onDraw", "onDraw " + mPath + "|" + mPaint);
long startTime = this.getDrawingTime();
Log.d("startTime", "startTime " + startTime);
mPaint.setColor(Color.WHITE);
c.drawPaint(mPaint);
// TODO: Ändern der Strichfarbe soll nicht komplett alles ändern, sondern nur den letzten Strich
if(strichFarbeHex != null){
String strichFarbHexCode = getStrichFarbe();
Log.d("strichFarbHexCode", "strichFarbHexCode " + strichFarbHexCode);
mPaint.setColor(Color.parseColor(strichFarbHexCode));
} else {
mPaint.setColor(Color.parseColor("#CD5C5C"));
}
canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
c.drawPath(mPath, mPaint);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
canvas = new Canvas(mBitmap);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// wenn die Zurücktaste das erste Mal gedrückt wurde
if (keyCode == KeyEvent.KEYCODE_BACK){
}
return true;
}
public static String setStrichFarbe(String strichFarbe){
strichFarbeHex = strichFarbe;
Log.d("strichFarbeHex", "strichFarbeHex " +strichFarbeHex);
return strichFarbeHex;
}
public String getStrichFarbe(){
return strichFarbeHex;
}
這張圖片顯示了它的樣子: 感謝您的幫助
該視圖中的「圖紙」,你應該消耗的觸摸事件,以防止任何進一步的行動正在採取在它上面(如滾動)。我猜目前還沒有發生,儘管我們確實需要看到一些相關的代碼來確認。 – 2014-09-12 12:35:39
您確定要爲寬度和高度都設置match_parent嗎? ScrollView在哪裏使用?你可以至少顯示一些od方法嗎?你確定你在繪圖時有不斷的drawingView尺寸嗎? – Pihhan 2014-09-12 12:39:17
我嘗試使用'wrap_content'和'layout_height'作爲'ScrollView','FrameLayout'和圖紙視圖。沒有改變。就在我用圖紙View使用'wrap_content'時,發生錯誤:「寬度和高度必須大於0」引用了Drawing類 – user3603935 2014-09-12 17:52:12