gridView with different cells sizes, pinterest style
I think a RecyclerView with StaggeredGridLayoutManager can solve this issue, and that if you wish to also have a fast-scroller, you can try this library.
So, no more trick are needed, as Google provided a solution...
GridView: GridView with different cells sizes and layout,
User RecyclerView
with GridLayoutManager
that have set SpanSizeLookup
. So it will be as follows:
int fullSpanSize = 3;
int normalSpanSize = 1;
GridLayoutManager layout = new GridLayoutManager(context, fullSpanSize);
layout.setSpaneSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
return position == 3 ? fullSpanSize : normalSpanSize;
}
});
recyclerView.setLayoutManager(layout);
Different Cell size grid for custom views
I used the following code to programmatically create views and set up their PercentRelativeLayout.LayoutParams
:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_percent_relative);
ViewGroup root = (ViewGroup)findViewById(R.id.perecent_layout_view);
View blueWidget = new View(this);
blueWidget.setBackground(blue);
root.addView(blueWidget);
setUpLayout(blueWidget, 2.0f/8.0f, 6.0f/8.0f, 6.0f/8.0f, 0.0f, 2.0f/8.0f, 0.0f);
View redWidget = new View(this);
redWidget.setBackground(red);
root.addView(redWidget);
setUpLayout(redWidget, 5.0f/8.0f, 2.0f/8.0f, 3.0f/8.0f, 0.0f, 0.0f, 6.0f/8.0f);
}
private void setUpLayout(View view, float widthPercent,
float heightPercent,
float leftMarginPercent,
float rightMarginPercent,
float topMarginPercent,
float bottomMarginPercent) {
PercentRelativeLayout.LayoutParams layoutParams = new PercentRelativeLayout.LayoutParams(view.getLayoutParams());
PercentLayoutHelper.PercentLayoutInfo percentLayoutInfo = layoutParams.getPercentLayoutInfo();
percentLayoutInfo.heightPercent = heightPercent;
percentLayoutInfo.widthPercent = widthPercent;
percentLayoutInfo.topMarginPercent= topMarginPercent;
percentLayoutInfo.bottomMarginPercent= bottomMarginPercent;
percentLayoutInfo.leftMarginPercent= leftMarginPercent;
percentLayoutInfo.rightMarginPercent= rightMarginPercent;
view.setLayoutParams(layoutParams);
}
The view looks like this:
How to design GridView with variable size of cell(images) in Android?
You may want to try out this third-party library called StaggeredGridView.
- http://www.androidviews.net/2013/01/pinterest-like-adapterview/
UICollectionView Dynamic Cell Height as per the content | Pinterest Layouts
What you have mentioned can be achieved using flow layout — a layout class provided by UIKit.
This is what you are looking for:
https://www.raywenderlich.com/392-uicollectionview-custom-layout-tutorial-pinterest
I hope you can put some effort into reading this very simple post and follow each step carefully.
Related Topics
How to Display Border to Imageview
Disable Soft-Keyboard from Edittext But Still Allow Copy/Paste
Get Gps Location in a Broadcast Receiver/Or Service to Broadcast Receiver Data Transfer
Android Studio 2.0 - Pause/White Screen on App First Run
Android Background Service Is Restarting When Application Is Killed
Google Play Services V13 Error Meta-Data in Androidmanifest
Noclassdeffounderror at Google Play Services V2 Library
Connect to SQL Server from Android
Set Live Wallpaper Programmatically on Rooted Device Android
Is My App or Its Dependencies Violating the Android Advertising Id Policy
Clear Text in Edittext When Entered
Can Android's Webview Automatically Resize Huge Images
Android - Add Textview to Layout When Button Is Pressed
How to Remove a Contact Programmatically in Android
How to Get Current Buildtype in Android Gradle Configuration
How to Handle Multiple Application Classes in Android