android - How to delegate touch events for ScrollView in background? -
i have specific requirement add 2 scrollviews framelayout. scrollview in background should display list of images , scroll along user touch feedback.
the scrollview on top should scrolled programmatically using smoothscrollto(x, y) method based on background scroll view position.
for this, must disable scroll event scrollview on top , allow background scrollview scroll along user touch event.
i disable scroll event scrollview on top unable scroll scrollview in background. need here.
i'hv pasted sample layout , java code below.
activity layout
<framelayout 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=".mainactivity"> <scrollview android:id="@+id/scrollview" android:layout_width="match_parent" android:layout_height="wrap_content"> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <view android:id="@+id/imageview" android:layout_width="match_parent" android:layout_height="250dp" android:background="#ff0000" /> <view android:id="@+id/imageview2" android:layout_width="match_parent" android:layout_height="250dp" android:background="#ffff00" /> <view android:id="@+id/imageview3" android:layout_width="match_parent" android:layout_height="250dp" android:background="#00ffff" /> </linearlayout> </scrollview> <scrollview android:id="@+id/list_scrollview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_centerhorizontal="true"> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <textview android:id="@+id/textview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="20dp" android:text="lorem ipsum dolor sit amet, consectetur adipiscing elit, sed eiusmod tempor incididunt ut labore et dolore magna aliqua. " android:textappearance="?android:attr/textappearancelarge" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="20dp" android:text="lorem ipsum dolor sit amet, consectetur adipiscing elit, sed eiusmod tempor incididunt ut labore et dolore magna aliqua. " android:textappearance="?android:attr/textappearancelarge" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="20dp" android:text="lorem ipsum dolor sit amet, consectetur adipiscing elit, sed eiusmod tempor incididunt ut labore et dolore magna aliqua. " android:textappearance="?android:attr/textappearancelarge" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="20dp" android:text="lorem ipsum dolor sit amet, consectetur adipiscing elit, sed eiusmod tempor incididunt ut labore et dolore magna aliqua. " android:textappearance="?android:attr/textappearancelarge" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="20dp" android:text="lorem ipsum dolor sit amet, consectetur adipiscing elit, sed eiusmod tempor incididunt ut labore et dolore magna aliqua. " android:textappearance="?android:attr/textappearancelarge" /> </linearlayout> </scrollview> </framelayout>
activity code
package com.javatechig.overscroll; import android.support.v7.app.actionbaractivity; import android.os.bundle; import android.view.menu; import android.view.menuitem; import android.view.motionevent; import android.view.view; import android.widget.scrollview; public class mainactivity extends actionbaractivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); scrollview textscrollview = (scrollview) findviewbyid(r.id.list_scrollview); textscrollview.setontouchlistener(new view.ontouchlistener() { @override public boolean ontouch(view v, motionevent event) { return true; } }); scrollview backgroundscrollview = (scrollview) findviewbyid(r.id.scrollview); backgroundscrollview.setontouchlistener(new view.ontouchlistener() { @override public boolean ontouch(view v, motionevent event) { return false; } }); } }
edit-1 have solve problem calling backgroundscrollview.ontouchevent(event); textscrollview ontouch() method. is appropriate? or have other way of doing this?
textscrollview.setontouchlistener(new view.ontouchlistener() { @override public boolean ontouch(view v, motionevent event) { backgroundscrollview.ontouchevent(event); return true; } });
i have solve problem calling backgroundscrollview.ontouchevent(event). works great.
textscrollview.setontouchlistener(new view.ontouchlistener() { @override public boolean ontouch(view v, motionevent event) { backgroundscrollview.ontouchevent(event); return true; } });
Comments
Post a Comment