How to create this layout with a RecyclerView? - android

I'm trying to create a recycler view with this type of layout. The items are strings and can apear with diferent sizes, i dont know how much items there will be in each row. Can I do this with a StaggeredGridLayoutManager?
The image is just a fake example, there can be more items in each row

You might wanna check out the open-source FlexboxLayout, developed by Google, especially FlexboxLayoutManager which is a layout manager for a RecyclerView.
To create the layout manager with the right config, just do this:
FlexboxLayoutManager layoutManager = new FlexboxLayoutManager();
layoutManager.setFlexWrap(FlexWrap.WRAP);
For more information, check out the Android Developers Blog's post.

Related

How to move items in a grid layout to center, if a row has less number of colums in android kotlin?

This isn't a grid layout, I've used custom views to create this. Can anyone help me to create this with gridview . Does this even possible with GridLayout?
This might or might not be possible via GridLayoutManager, but there is no direct solution to get this using GridLayoutManager. I suggest you take a look at Flexbox layout manager here:
https://github.com/google/flexbox-layout
This is from Google and what you want can easily be done using it instead. You might need to play around with the properties a bit, but I think it can be done using the justifyContent property.
A rough code snippet would be something along the lines of
RecyclerView recyclerView = (RecyclerView) context.findViewById(R.id.recyclerview);
FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(context);
layoutManager.setFlexDirection(FlexDirection.ROW);
layoutManager.setJustifyContent(JustifyContent.SPACE_AROUND);
recyclerView.setLayoutManager(layoutManager);

How to design a dynamic cardView in android such that two cardViews are adjacent to one another?

I am trying to implement cardView in android, such that two cards lay adjacent to one another as shown in the image below:
enter image description here
However, I am following this tutorial. The problem with this tutorial is that in this, each row contains a single cardView element; but I need two cardViews adjacent to one another. What change should I make in the code such that two cardViews are adjacent to one another instead of one.
I am adding the cardViews dynamically. That is there is no fixed size for the number of cardViews.
In the Activity Main onCreate change
mLayoutManaget = new LinearLayoutManager(this)
to
mLayoutManaget = new GridLayoutManager(this, 2)
where 2 is the Number of Columns
What you're seeing is a RecyclerView (a list) of CardViews... presented in the default RecyclerView layout manager: LinearLayoutManager.
What you should do instead, is try using the GridLayoutManager and provide 2 columns.
You can check your XML to see if you have it defined there (if so, just remove it) and do it in code with something like:
yourRecyclerView.setLayoutManager(new GridLayoutManager(context, 2));
You get the idea (I hope).

Expanding recycler view items

I have gone through other questions as well but couldn't figure out something. I have a well set up RecyclerView.
I m trying this library: https://github.com/AAkira/ExpandableLayout
Now I want the items to be expandable so that they show a TextView which is different for each item.
But I can't figure out how to place itms in XML. Where to place RecyclerView and where the expandable layout? How to setup these things?
Take a look at one of the samples given in the library, it is called 'examplerecyclerview' which I think is the one you need.
These are specific files that you should watch:
RecyclerView Activity and Adapter (Java)
RecyclerView Activity (XML)
RecyclerView List Row (XML)

Android Customizable Expandable List View Item

My problem is simple: I need to make a layout similar to android.R.layout.simple_expandable_list_item_1 which can fit more than one textview in the layout, as well as show the little '>' symbol that indicates that the tab is expandable.
How can this best be accomplished? My first thought was to use the layout as a background of a linear layout with two textviews in it, but I can't seem to make that work.
Vogella has a pretty good tutorial on how to achieve custom list views through Adapters.
Basically, what you do is you create a Layout with the looks you want for the list items and then you extend an adapter (ArrayAdapter for instance), see section 4. Then, in your activity, you create an instance of your Adapter implementation and populate it from an Array containing the data for the list.
Also have a look at the Developers site for how to make the list scroll smoothly with the ViewHolder pattern.
And if you feel you need more info on the expandable part maybe the hive can help.

Clickable TextViews in Staggered GridView

I am trying to show dynamic list of strings in GridView. Every word will be clickable and can be selected or deselected. I am attaching a screenshot of Flipboard as I want exactly the same functionality.
Please help me to find out the same functionality to be implemeted in my app.
The simplest way and without any external libraries you can use native components Gridview or recyclerview with GridLayoutManager
Follow this steps :
1 - Design your row item it's means the click-able labels in separated xml file.
2 - Create your adapter class to inflate view, show the data and handle clicks.
3- attach adapter to gridview or recyclerview.
And her is example for RecyclerView with GridLayoutManager and other one for Gridview
You can use this or this libraries to do this type of functionality

Categories

Resources