Android GridLayout Equal Column Widths

Just use column weight for GridLayout’s children: android:layout_width=”0dp” android:layout_columnWeight=”1″ Remember using support library if your project’s MinSdk < API 21: implementation ‘com.android.support:appcompat-v7:27.1.1’ implementation ‘com.android.support:gridlayout-v7:27.1.1′ You should use android.support.v7.widget.GridLayout instead of GridLayout. And don’t forget using app namespace when using support library: xmlns:app=”http://schemas.android.com/apk/res-auto” android:layout_width=”0dp” app:layout_columnWeight=”1″ UPD: If you make your GridLayout programmatically, use GridLayout.Spec. For example: … Read more

gridView with different cells sizes, pinterest style

Is it a bit late to answer? check this library from etsy. it looks very promising. https://github.com/etsy/AndroidStaggeredGrid I think it is newer version of https://github.com/maurycyw/StaggeredGridView . Updated. Try using RecyclerView StaggeredGridLayoutManager from google instead RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view); recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)); recyclerView.setItemAnimator(new DefaultItemAnimator()); recyclerView.setAdapter(adapter);

How do I set android:layout_columnWeight=”1″ programmatically to an element in an android support v7 Gridlayout

I found this method from GridLayout: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.0.0_r1/android/widget/GridLayout.java#GridLayout.spec%28int%2Cfloat%29 So maybe you could try something like this: ((GridLayout.LayoutParams) this.getLayoutParams()).columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1f);

Textview with long text pushes out other views in GridLayout despite ellipsize=end

I seem to have found a potential solution to prevent a TextView in GridLayout from growing unboundedly and pushing out other views. Not sure if this has been documented before. You need to use fill layout_gravity and set an arbitrary layout_width or width on the long TextView in need of ellipsizing. android:layout_gravity=”fill” android:layout_width=”1dp” Works for … Read more

Android – Difference between Gridlayout and Staggered Gridlayout

Grid View : It is is a ViewGroup that displays items in a two-dimensional, scrollable grid. In this each Grid is of same size (Height and width). Grid View shows symmetric items in view. Staggered Grid View : It is basically an extension to Grid View but in this each Grid is of varying size(Height … Read more

GridLayout Column width

This code is available on pre API21 with support library! I have a simple piece of code to show 4 buttons in a gridLayout of 2 columns that take 50% of the available space: perhaps it can help <GridLayout android:id=”@+id/grid” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:columnCount=”2″ > <Button android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Button” android:layout_gravity=”fill” android:layout_columnWeight=”1″ /> <Button android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Button” … Read more

Changing number of columns with GridLayoutManager and RecyclerView

If you have more than one condition or use the value in multiple places this can go out of hand pretty fast. I suggest to create the following structure: res – values – integers.xml – values-land – integers.xml with res/values/integers.xml being: <?xml version=”1.0″ encoding=”utf-8″?> <resources> <integer name=”gallery_columns”>2</integer> </resources> and res/values-land/integers.xml being: <?xml version=”1.0″ encoding=”utf-8″?> <resources> … Read more

GridLayoutManager – how to auto fit columns?

You can calculate available number of columns, given a desired column width, and load the image as calculated. Define a static funtion to calculate as: public class Utility { public static int calculateNoOfColumns(Context context, float columnWidthDp) { // For example columnWidthdp=180 DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); float screenWidthDp = displayMetrics.widthPixels / displayMetrics.density; int noOfColumns = (int) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)