Is there any way to create a recycler where its first cell is twice as big as the other cells and all the other cells are in between the top and bottom of the first cell. Here is a drawing example because I can not explain it properly with words.
Create a POJO class for each different view types and pass the values to the POJO classes and add the POJO as the recycler view item.You can insert and render multiple view types inside a recycler view .
Related
I am doing a small Android game where the user needs to assign two players to two teams.
My plan is to use a recycler view which lists all existing players (which are stored in a local database).
The items in the recycler view will be possible to reorder. The first two items in the recycler view will be assigned to team A and the next two items will be assigned to team B. The remaining players will not be considered in a team. The implementation of this logic will be fine, there are also enough examples in the web.
But in order to indicate this logic to the user, I would like to offer him some kind of boxes which indidcate the teams. Like in the following wireframe:
Does anybody have an advice how this should be done? Should I put a View above the recycler view?
Alternatively, I am also open for alternative approaches to assign exactly two players (uniquely) to two teams.
If you want use RecyclerView, you need to include divider in item view, or make divider as item itself.
You need to place these Divider backgrounds below recyclerview, calculate heights of these items and place it accordingly.
I display my JSON data into a RecyclerView. I have multiple TextView into one item and it works perfectly.
In my data, I need to fetch photos and display them into each item. I have multiple photos for one item. It starts from 6 photos to... many more.
I tried using a RecyclerView inside my first RecyclerView but as you can guess it was a bad idea (bad performance, not the good result expected and so on).
Do you have any other solution or advice that might help, please?
I found a thousand solutions how to display one picture by row but none about multiple pictures into one row.
Create a custom view and add Image views dynamically based on no.of views required.
Use this view in the recycler view adapter itemlayout file.
Given this scenario :
image
I'm trying to position every child elements of the gridview such that it will have specific margin value with the gridview child element that is directly above the element, and I would like the margin value (the vertical spacing between each child) to be consistent in relation to the Gridview child element directly above it.
From the context of the image uploaded above, I want to minimize the spacing between each child elements vertically given the case that each Gridview element's height is variable and I intend to keep it this way.
I'm also using a custom adapter to supply the items for the GridView.
Is there any method/XML attribute in a GridView class I can use to perform this task or do I need to use a custom view and override from GridView to implement this feature?
Thanks in advance.
Well apparently GridView does not support this kind of implementation and I'll have to resort to using StaggeredGridLayoutManager.
Displaying a certain layout for a card, when using CardView, is simple enough.
I've created an XML layout for my card, and instantiate that XML layout to the View using LayoutInflater.
More specifically:
View largeCardView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.card_view, viewGroup, false);
Which is called in the onCreate() method of my RecyclerAdapter. The onCreate method then returns this largeCardVew. This works perfectly and the cards are displayed as they are laid out in the XML file.
But what if I want to display different cards for different content? Is it possible to show different cards for different things, but have them all in the same RecyclerView?
For example, if I know before hand that there will be a string passed into a TextView in the card, and this string can only have two values "Large" and "Small", how can I use one type of XML file to use with the "Large" text, and another XML file to use with the "Small" text?
Here is an example (taken from Google Play):
As you can see in the picture, there are two different card types, with different layouts (ignore the orange button). Is there a way to achieve a similar thing, and have the cards in the same RecyclerView?
It's similar to how you would create a single card layout, but instead of having a single .xml and a single ViewHolder, each layout needs to have its own .xml file defining it, and a ViewHolder class.
The method which was found to be very important, is the getItemViewType(int position) method in the RecyclerView.Adapter class. By default, this method returns 0, assuming a single layout for the viewType being used (in this case, a cardView). Since more than a single type is needed, I had to define them.
I then created an array of integers (called cardViewTypes), defining which layouts get used for which type of data. Since you should already have some sort of dataset for the content of the cards (whether it's a List or a HashMap), it's important to make sure that the data matches up with the view types.
In my case, I wanted to have 4 different card layouts, so I defined each in their own .xml file and gave them unique names. Then, in my RecyclerView.Adapter class, I created a separate class which extended ViewHolder for each layout. I made sure that each integer in my viewType array matched up with my data and called getItemViewType.
I then check the view type in the onCreateViewHolder method of the RecyclerView.Adapter, and inflate the corresponding view, which is then bound in onBindViewHolder(ViewHolder, int).
And the result is differing card layouts for different content.
In the past when I have needed to display large data sets in a table, I've just looped over the data and on every iteration I'd inflate an xml layout representing a TableRow, obtain references to the child controls, set their properties from the data source and add the row to a TableLayout. When just displaying simple rows of data or items in a grid, I use an adapter. Am I doing this correctly, or is there a way to use an adapter to display tabular data with column alignment like in a TableLayout? Or, is there some way to apply the ViewHolder pattern to the way I'm manually adding rows to a TableLayout to avoid the extra calls to inflate xml and get references to child controls (findViewById)?