Such as ListView, it invokes smoothScrollToPosition(index)
Android Developer Doc doesn't have HorizontalListView. I downloaded this custom HorizontalListView from GitHub, but I'm confused about how to use HorizontalListView on scrolling automatically.
could recyclerview scroll loop, and it scroll in specified time
I recommend using recyclerview with a linear layout manager that is set in horizontal mode
If you need only a HorizontalListView RecycleView is the way to go.
Just add this line of code to convert it to a HorizontalListView
LinearLayoutManager layoutManager= new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL, false);
mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(layoutManager);
Refrence can be found here https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html
you can use recycle view and set layout manager as follows
listView= (RecyclerView)findViewById(R.id.hlistview);
LinearLayoutManager layoutManager=new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false);
listView.setLayoutManager(layoutManager);
See this example on github
Related
Is it possible to show multiple text in a recycler view/carousel view in android/kotlin.If yes,then what would be the logic for that or what topic should I read that will help me with this.
I have attached a example diagram below.I want to create the below part,there is some other layout on top :
Really need some help over here.
Yes, I believe you're looking for a StaggeredGridLayoutManager for RecyclerView.
For example, when setting up your RecyclerView, set your LayoutManager to a new StaggeredGridLayoutManager.
// get the reference of RecyclerView
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
// set a StaggeredGridLayoutManager with 3 number of columns and vertical orientation
StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(3, LinearLayoutManager.HORIZONTAL);
recyclerView.setLayoutManager(staggeredGridLayoutManager); // set LayoutManager to RecyclerView
A more in-depth example could be found here, https://abhiandroid.com/materialdesign/recyclerview-as-staggered-grid-example.html.
How to make a GridView look something like that?
I found similar library but it is implemented using ListView and I want using RecyclerView.
Thanks.
To do this use RecylerView and StaggeredGridLayoutManager
recyclerView = findViewById(R.id.recycler_view);
mAdapter = new YourAdapter(yourParameters);
recyclerView.setLayoutManager(
new StaggeredGridLayoutManager(spanCount /*in your case number of columns*/, StaggeredGridLayoutManager.VERTICAL /*orientation*/));
recyclerView.setAdapter(mAdapter);
I have n items in a list. i.e Item1 ,Item2,Item3..Item-n. I want to open them on the click of a button and make them visible in a horizontal manner. For Example
ITEM1 ITEM2 ITEM3......ITEM-N
How to draw the same in xml design in android.
Please help to solve the same.
Use like it
xml layout
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView_category"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
Use in Activity class:
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView_home_10);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(MainActivity.this, LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(layoutManager);
// If using recylerview in srollview
recyclerView.setNestedScrollingEnabled(false);
// set Adapter
recyclerView.setAdapter(adapter);
LayoutManager is the class that layout views in RecyclerView. So change recyclerView.setLayoutManager(LayoutManager) if you want to change layout. In your case, if you use LinearLayoutManager, do this by calling:
LinearLayoutManager layoutManager = ...
recyclerView.setLayoutManager(layoutManager);
//when you want horizontal
layoutManager.setOrientation(context,LinearLayoutManager.HORIZONTAL,false);
//when you want vertical
layoutManager.setOrientation(context,LinearLayoutManager.VERTICAL,false);
RecyclerView is shown with vertical orientation, and can not set this property, because orientation belongs to the LinearLayoutManager object. Any way to simulate HORIZONTAL layout?
Anyway the linearLayoutManager created in code is set to HORIZONTAL.
llm.setOrientation(LinearLayoutManager.HORIZONTAL);
try to add these parameters to your RecyclerView inside your layout xml:
android:orientation="horizontal"
android:scrollbars="horizontal"
app:layoutManager="LinearLayoutManager"
RecyclerView won't show your actual data in the Editor Layout as the data you add in your RecyclerView is added Dynamically in your java code through Adapter and you implement a layout manager for your recyclerView in your java code and your Editor Layout displays the elements that are in your xml, so in your XML file its just a plain recyclerView which has no idea of what data is added in your Java implementation or what LayoutManager is to be implemented on it.
AFAIK, there is no such facility editor provide yet.
although you can set the orientation of LinearLayoutManager Horizontal at runtime, this will fulfill your requirement.
LinearLayoutManager layoutManager
= new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
How can I implement something like this so I could customize each view in the grid? (each one its own image, text.. depending on a response from server).
**I prefer not using 3-party libraries, if that's possible.
You can set up Horizontal RecyclerView, and based on the position of the view, you can set background color.
LinearLayoutManager layoutManager
= new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
RecyclerView myList = (RecyclerView) findViewById(R.id.my_recycler_view);
myList.setLayoutManager(layoutManager);