Reputation: 622
I want to make a LinearLayout
(to which I'm adding items dynamically) scrollable inside a scrollable RecyclerView
. On startup, I can see a little scrollbar initially (indicating it's a scrollable view, fades in seconds). Tried appCompat NestedScrollView as well as enabling nestedScrollingEnabled
, with no success. How can I make the LinearLayout
scrollable inside the RecyclerView
?
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="300dp"
android:fillViewport="true"
android:nestedScrollingEnabled="true">
<LinearLayout
android:id="@+id/playerlist_linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left|center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="7dp"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
</FrameLayout>
RecyclerView code
<android.support.v7.widget.RecyclerView
android:id="@+id/messagesListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1"
android:nestedScrollingEnabled="false"/>
UPDATE: I found out that scrolling does indeed work, but only if I spam the mouse or tap really fast inside the scrollview. It kind of gets focused and allows scrolling as long as mouse is held down. Really strange.
Upvotes: 1
Views: 6630
Reputation: 17
I finally found an another way how the ScrollView can be scrolled inside RecyclerView viewHolder. I originally posted my answer here, so you can look up my answer for how I can enabled the scroll of ScrollView inside RecyclerView. Hope this will help on someone who look up another answer.
But I also want to answer from the OP's question why there is a little scrollbar on the ScrollView. You can hide the scrollbar by adding android:scrollbars="none"
in your ScrollView tag in xml layout and also remove android:nestedScrollingEnabled="true"
because it is no use in this case.
<ScrollView
android:layout_width="wrap_content"
android:layout_height="300dp"
android:fillViewport="true"
android:scrollbars="none">
<LinearLayout
android:id="@+id/playerlist_linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left|center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="7dp"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
Upvotes: 0
Reputation: 622
I solved it by adding a line to rafsanahmad007's solution:
ScrollView scrollView = (ScrollView)findViewById(R.id.scrollView1);
scrollView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
// Disallow the touch request for parent scroll on touch of child view
view.getParent().requestDisallowInterceptTouchEvent(false);
view.onTouch(motionEvent);
return true;
}
});
I'm not sure that's how View.onTouch
is called on Java, as I'm developing with Xamarin.Android (C#). It should be pretty similar.
Upvotes: 3
Reputation: 23881
Try disabling the touch of recycler view when scrollview
is being touched.
ScrollView scrollView = (ScrollView)findViewById(R.id.scrollView1);
scrollView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
// Disallow the touch request for parent scroll on touch of child view
view.getParent().requestDisallowInterceptTouchEvent(false);
return true;
}
});
Upvotes: 4