java - Android: stop scrolling when imageview is touched? -
i try make possible rotate imageview, scrolling gets in way. how can stop scrolling while imageview touched? don't think code necessary, here goes: fragment_main.xml
<scrollview xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/scrollview01" android:layout_width="fill_parent" android:layout_height="fill_parent" > <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".mainactivityfragment" android:background="@drawable/texture"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Πάγωσε η κόλαση..." android:textcolor="@color/label_color" android:textsize="20dp" android:id="@+id/label_0" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:paddingtop="25dp" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Μπρρρ!" android:textcolor="@color/label_color" android:textsize="20dp" android:id="@+id/label_1" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:layout_margintop="50dp" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Κρύο" android:textcolor="@color/label_color" android:textsize="20dp" android:id="@+id/label_2" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:layout_margintop="75dp" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Έτσι κ'έτσι..." android:textcolor="@color/label_color" android:textsize="20dp" android:id="@+id/label_3" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:layout_margintop="100dp" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Καλό" android:textcolor="@color/label_color" android:textsize="20dp" android:id="@+id/label_4" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:layout_margintop="125dp" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Πολύ καλό!" android:textcolor="@color/label_color" android:textsize="20dp" android:id="@+id/label_5" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:layout_margintop="150dp" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Κάνεις κοιλιακούς!" android:textcolor="@color/label_color" android:textsize="20dp" android:id="@+id/label_6" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:layout_margintop="175dp" /> <imageview android:src="@drawable/thermostat" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/thermostat" android:layout_centervertical="true" android:layout_centerhorizontal="true" android:layout_margintop="@dimen/margin" /> <imageview android:src="@drawable/thermostat_slider" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/thermostat_slider" android:layout_centervertical="true" android:layout_centerhorizontal="true" android:layout_margintop="@dimen/margin" /> <imageview android:src="@drawable/inside_thing" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/inside_thing" android:layout_centervertical="true" android:layout_centerhorizontal="true" android:layout_margintop="@dimen/margin" /> <imageview android:src="@drawable/inside_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/inside_text" android:layout_centervertical="true" android:layout_centerhorizontal="true" android:layout_margintop="@dimen/margin" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancelarge" android:text="Τι κάνω?" android:textcolor="@color/label_color" android:textstyle="bold" android:id="@+id/title" android:layout_centerhorizontal="true" android:layout_margintop="@dimen/title_margin"/> <edittext android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/text" android:text="@string/help_text" android:textcolor="@color/label_color" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:layout_margintop="750dp" /> </relativelayout> </scrollview>
you cannot disable scrolling of scrollview
. need extend scrollview , override ontouchevent
method return false when condition matched.
public class lockablescrollview extends scrollview { private boolean mscrollable=true; public lockablescrollview(context context, attributeset attrs, int defstyle) { super(context, attrs, defstyle); // todo auto-generated constructor stub }
override required methods , constructors
@override public boolean ontouchevent(motionevent ev) { switch (ev.getaction()) { case motionevent.action_down: // if can scroll pass event superclass if (mscrollable) return super.ontouchevent(ev); //return mscrollable condition false /* *write code here implement functionality if image view touched */ // continue handle touch event if scrolling enabled return mscrollable; // mscrollable false @ point // mscrollable flag may //use condition default: return super.ontouchevent(ev); } } @override public boolean onintercepttouchevent(motionevent ev) { switch (ev.getaction()) { case motionevent.action_down: // if can scroll pass event superclass if (mscrollable) return super.onintercepttouchevent(ev); // continue handle touch event if scrolling enabled return mscrollable; // mscrollable false @ point default: return super.onintercepttouchevent(ev); } }
Comments
Post a Comment