I am using a Recycler view inside a Horizontal Scroll View to display threaded comments like below:
Comment1
Comment1Child1
Comment1Child2
Comment1Child2Child1
Comment1Child3 Comment2
etc.
I have done this with the following XML:
<HorizontalScrollView
android:id="#+id/horizontalScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbarSize="2dp">
<android.support.v7.widget.RecyclerView
android:id="#+id/commentRV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_marginLeft="47dp"
android:minWidth="200dp" />
</HorizontalScrollView>
You'll see I set a min width of 200dp so that the comments never get too small and the deeper down the thread they go the further off screen it will be pushed.
It is displaying perfectly but I am unable to scroll horizontally. I can see the scroll bars but I cannot scroll horizontally.
I have fiddled with disabling Touch and nestedScrollingEnabled in the RV but not sure what the real solution is. Nothing seems to work?
Any help would be much appreciated! Thank you
Remove HorizontalScrollView you can give LinearLayoutManager with horizontal orientation like this
LinearLayoutManager layoutManager= new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
reclyclerView.setLayoutManager(layoutManager);
//recyclerView.setMinimumWidth(200); optional for width if u need
Related
When scrolling from left half screen of the mobile scrolling is happening but when i scroll from right half screen scroling is not happening.
This is my xml clode.
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/postRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_margin="2dp"
android:nestedScrollingEnabled="false">
</androidx.recyclerview.widget.RecyclerView>
My Java code is
val layoutManager = LinearLayoutManager(this)
layoutManager.orientation = LinearLayoutManager.VERTICAL
binding.postRecyclerView.layoutManager = layoutManager
binding.postRecyclerView.setHasFixedSize(false)
enter code here
Finally after so much search i found the solution. Actually i have used Floating button in that page due to that hieght from right side scrolling was not happend in Recyclerview.
I want my RecyclerView to wrap_content. I don't want any scrolling inside RecyclerView, it should adjust to the height of inner children. I wan't my parent ScrollView to scroll the content of my activity.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- scrolls a little bit as RecyclerView goes slightly down beyond the screen -->
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- still scrolls inside -->
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Populate RecyclerView:
myAdapter = new MyAdapter();
layoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerView.setAdapter(myAdapter);
I use RecyclerView library where wrap_content issues should be fixed:
dependencies {
compile 'com.android.support:recyclerview-v7:25.0.0'
}
Basically RecyclerView height calculation doesn't work well for me here. RecyclerView still has it's own scroll and ScrollView scrolls a little as well. If I try to set some rediculous RecyclerView height to 1000dp so that it's bigger than height of items in total, scrolls work as needed e.g. RecyclerView doesn't scroll and ScrollView scrolls the activity with all RecyclerView items.
So what did I do wrong? :)
All I needed is to use android.support.v4.widget.NestedScrollView instead of a ScrollView.
In that case you need to upgrade your recyclerview gradle version, if you are using 23.0.1 make it 23.1.1 or higher version. In the latest gradle update google has provided the wrap_content property to recyclerview.
I'm developping a Android app, and I got a vertical NestedScrollView, who take all my screen, and inside multiple hoizontal RecyclerView. It's work, but the horizontal scroll is really hard to achieve.
I mean, when I scroll horizontally the gesture is catch by the NestedScrollView, and the view move up/down. I need to focus and do a real horizontal movement to scroll the RecyclerView, it's killing UX...
Here my NestedScrollView :
<android.support.v4.widget.NestedScrollView
android:id="#+id/scrollView"
android:scrollbars="none"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/scrollLayout"
android:orientation="vertical" />
</android.support.v4.widget.NestedScrollView>
I'm inflating RecyclerView programmatically, because the number is define in network data, here the inflated layout :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:textSize="#dimen/secondary_text_size"
android:textAllCaps="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="#dimen/recycler_view_size" />
</LinearLayout>
And how I set my RecyclerView in Java :
LayoutInflater inflater = LayoutInflater.from(context);
LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.recycler_view_layout, null, false);
RecyclerView recyclerView = (RecyclerView) layout.findViewById(R.id.recyclerView);
LinearLayoutManager layoutManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
recyclerView.setHasFixedSize(false);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(this);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setNestedScrollingEnabled(false);
I tried to change the "velocity" NestedScrollView, but I can't find good advice/post, maybe I don't find the good one. Someone can help ?
Hope you find it useful, as I think you need to implement one of these libraries (on GitHub you would find more):
View Flow for Android: https://github.com/pakerfeldt/android-viewflow
HorizontalListView: https://github.com/MeetMe/Android-HorizontalListView
TwoWayGridView https://github.com/jess-anders/two-way-gridview
If you want to do it with standard Android libraries, RecyclerView might be useful if you want to scroll horizontally
To prove that it has horizontally scrolling support, take a look at:
public boolean canScrollHorizontally ()
Query if horizontal scrolling is currently supported. The default
implementation returns false.
Returns True if this LayoutManager can scroll the current contents horizontally
or
public int computeHorizontalScrollExtent (RecyclerView.State state)
Override this method if you want to support scroll bars.
Read computeHorizontalScrollExtent() for details.
Default implementation returns 0.
From: https://developer.android.com/reference/android/support/v7/widget/RecyclerView.LayoutManager.html
Check also subclass of RecyclerView called HorizontalGridView
Hope it help.
I'm using a RecyclerView inside a SwipeRefreshLayout in Android.
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/mySwipeRefresh"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<RecyclerView
android:id="#+id/myRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
In this RecyclerView i'm using a LinearLayoutManager with reverse layout and stack from end:
LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
layoutManager.setReverseLayout(true);
layoutManager.setStackFromEnd(true);
myRecyclerView.setLayoutManager(layoutManager);
So, the scrolling content starts from bottom and items are added by adapter from bottom to top.
With this configuration, i'd like to show SwipeRefreshLayout when RecyclerView is at the bottom and user try scrolling more down. Instead, the results is that SwipeRefreshLayout has the standard behavior and is shown from top to bottom animation when user scrolls to top and RecyclerView is at the top.
I didn't find apis to do this, how can i solve this issue?
Thanks
I resolved using this library since SwipeRefreshLayout doesn't support reverse layout
Refresh layout bottom
I am doing a task which retrieves images from server and displays in GridView in the application. This Grid view is scrolling up and down. But i want to scroll this view left to right as the menu screen scrolls.
Is it possible with grid view? Or Is there any better way to do this? please help me in doing this.
thanks in advance.
This isn't easily possible with the stock Android GridView. Try using this library:
two-way-gridview
(I found this library in this other answer: Horizontal scrolling grid view)
Is there any better way to do this?
Yes, there is.
You can achieve this in 3 lines using a RecyclerView with a horizontal GridLayoutManager:
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rec1);
recyclerView.setLayoutManager(new GridLayoutManager(this, 2, GridLayoutManager.HORIZONTAL, false));
recyclerView.setAdapter(new CustomAdapter(arrayList));
The RecyclerView supports applications built with the SDK 7 or larger.
If you want to make it even easier, take a look at the HorizontalGridView class if you are working with an application that is built for the API 17 or larger.
Here's a link of an example of a simple RecyclerView Adapter.
Try with below layout
<HorizontalScrollView android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<GridView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/gridview" android:columnWidth="50dp" android:padding="10dp"
android:horizontalSpacing="8dp" android:verticalSpacing="12dp"
android:numColumns="3" android:scrollbars="horizontal"/>
</HorizontalScrollView>