I want to result like this:
which can do horizontal-scrolling.
But in fact, like this below:
Which can't display all item and not horizontal-layout.
who can help me ? thanks. other way can reach my wanted result here?
You need to add Layout manager to RecylerView.
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
recylcerView.setLayoutManager(layoutManager);
This will make the RecylerView horizontal.
To set recyclerView as horizontal scrollView you can use LinearLayoutManager. by default it sets vertical scroll behaviour.
LinearLayoutManager layout = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);//0 Horizontal , 1 vertical
recyclerView.setLayoutManager(layout);
in layout.xml
<android.support.v7.widget.RecyclerView
android:id="#+id/yourRecyclerView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/layout_past_round_header"
android:layout_centerInParent="true"
android:overScrollMode="never" />
in your NestedScrollView add this
android:fillViewport="true"
Related
I'm using recycler view with a layout that consists of 4 text views but I want to display more than 5 columns in the layout with horizontal scroll view? Is it feasible and possible? If yes, can anyone share any link or code?
Thank you.
For Horizontal scroll view, set your RecylerView layoutManager as follows,
LinearLayoutManager linearLayoutManager
= new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
RecyclerView recyclerView=(RecyclerView) findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(linearLayoutManager);
In RecyclerView ,
android:layout_width="match_parent"
android:layout_height="0dp"
In RecyclerView item layout,
android:layout_width="wrap_content"
android:layout_height="wrap_content"
This code works as intended:
LinearLayoutManager layoutManager = new LinearLayoutManager(this,
LinearLayoutManager.VERTICAL, false);
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.scrollToPosition(2);
The positioning and scroll are vertical and third item is displayed.
Now, if in the above code VERTICAL is replaced with HORIZONTAL, items are displayed horizontally and scroll is horizontal (as intended), but setScrollToPosition(2) doesn't work anymore.
How to scrollToPosition with HORIZONTAL LinearLayoutManager?
My XML file is mentioned below:
< android.support.v7.widget.RecyclerView
android:id="#+id/rvPosters"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="4dp"
android:paddingBottom="4dp" >
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
Forgive me for any mistakes. I'm a beginner.
Can anyone please explain how to create a listview inside a cardview layout in android. Example settings app in android 6.0
I wanna create a scrollable cardview layout with listview items in each cardview layout.
I have searched enough online and nothing seems to help me.
If you have any solution this it would be helpful for me.
The best way to do this is using a RecyclerView with a vertical LinearLayoutManager (which will look the the same as a ListView but with better performance) and a fixed size inside your CardView. The xml for your CardView will look something like this:
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.v7.widget.CardView>
and then programmatically set fixed size on your RecyclerView to true, set the LayoutManager and create a custom RecyclerView.Adapter to fill the RecyclerView's rows:
RecyclerView recyclerView = parentView.findViewById(R.id.recyclerview);
recyclerView.setHasFixedSize(true);
LinearLayoutManager layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(layoutManager);
MyCustomAdapter adapter = new MyCustomAdapter(context, dataSet);
recyclerView.setAdapter(adapter);
The cardView is a backgroud of the listView. So the item of this will like:
enter image description here
Hope to help you!
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