I solved this problem. Posting this for someone who is facing the same problem now / in the future. Thank you for the offer of Mahesh. Based on Maheshโs assumption, I did so. This is my layout.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/scroll_view" android:background="#ffffff" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/bg_tv" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="TestView" android:layout_marginTop="5dip"/> <View android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/background_dark" android:alpha="0" /> <ScrollView android:id="@+id/sv" android:layout_width="fill_parent" android:layout_height="wrap_content" > <LinearLayout android:id="@id+/wrapper" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@android:color/transparent" android:orientation="vertical" > <LinearLayout android:id="@+id/dummy" android:layout_width="fill_parent" android:background="@android:color/transparent" android:layout_height="500dip" android:orientation="vertical"/> <LinearLayout android:id="@+id/scroll_" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > ................ ................ </LinearLayout> </LinearLayout> </ScrollView> </RelativeLayout>
After adding LinearLayouts @ id / dummy and @ id / scroll_, I could not click on TextView @ id / bg_tv. The following code solved my problem.
//dispatch touch events mDummyView = findViewById(R.id.dummy); mDummyView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { mTextView.dispatchTouchEvent(motionEvent); return true; } }); mLayout = (LinearLayout)findViewById(R.id.scroll_); mLayout.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { if (scrollPercent <= 0.25f) { mTextView.dispatchTouchEvent(motionEvent); return true; } return false; } });
In the case of mlayout, TouchEvents are dispatched only after scrollView has moved to the bottom of the screen.
PS: I am writing an answer for the first time. I'm sorry if you think the formatting is very bad or the answer is not written the way it should be.
source share