java - Drawing area with ScrollView -
i´m creating painting , drawing area in activity , move scrollview.
if have code don´t have problem:
<relativelayout android:id="@+id/framever" android:layout_width="match_parent" android:layout_height="2000dip" android:layout_marginbottom="3dp" android:layout_marginleft="5dp" android:layout_marginright="5dp" android:layout_margintop="3dp" android:layout_weight="1" android:background="@null"> <package.drawingview android:id="@+id/drawing" android:layout_width="fill_parent" android:layout_height="2000dip" android:background="@null" /> </relativelayout>
but, if add scrollview, paints in pieces:
<package.linkablescrollview android:id="@+id/scrollview" android:layout_width="fill_parent" android:layout_height="2000dip" android:layout_marginbottom="3dp" android:layout_marginleft="5dp" android:layout_marginright="5dp" android:layout_margintop="3dp" android:layout_weight="1" android:background="@null"> <relativelayout android:id="@+id/framever" android:layout_width="match_parent" android:layout_height="2000dip" android:layout_marginbottom="3dp" android:layout_marginleft="5dp" android:layout_marginright="5dp" android:layout_margintop="3dp" android:layout_weight="1" android:background="@null"> <package.drawingview android:id="@+id/drawing" android:layout_width="fill_parent" android:layout_height="2000dip" android:background="@null" /> </relativelayout> </package.linkablescrollview>
if paint in portrait mode, lets me draw, in pieces, , if paint in landscape can paint perfectly.
i have created mi own scrollview enabling or disabling property, paints in same way.
public class linkablescrollview extends scrollview { private static final int number_of_fingers_to_activate_scroll = 2; private boolean doubledrag = false; private boolean enablescrolling = true; public linkablescrollview(context context, attributeset attrs, int defstyle) { super(context, attrs, defstyle); } public linkablescrollview(context context, attributeset attrs) { super(context, attrs); } public linkablescrollview(context context) { super(context); } private int getscrollheight() { return super.getchildat(0).getheight() - super.getheight(); } public boolean isenablescrolling() { return enablescrolling; } public void setenablescrolling(boolean enablescrolling) { this.enablescrolling = enablescrolling; } @override public boolean ontouchevent(@nonnull motionevent event) { if (isenablescrolling()) { int action = event.getaction(); switch (action) { case motionevent.action_down: super.ontouchevent(event); break; case motionevent.action_pointer_up: break; case motionevent.action_up: super.ontouchevent(event); doubledrag = false; break; case motionevent.action_move: if (event.getpointercount() == number_of_fingers_to_activate_scroll) { doubledrag = true; } if (doubledrag) { super.ontouchevent(event); } } return true; } else { return false; } } }
draw touch event:
@override public boolean ontouchevent(motionevent event) { point p = new point(); float touchx = event.getx(); float touchy = event.gety(); switch (event.getaction()) { case motionevent.action_down: drawpath.moveto(touchx, touchy); break; case motionevent.action_move: drawpath.lineto(touchx, touchy); break; case motionevent.action_up: drawcanvas.drawpath(drawpath, drawpaint); drawpath.reset(); break; default: return false; } invalidate(); return true; }
please, can me? thanks!
Comments
Post a Comment