Search code examples
androidandroid-gridlayout

Gridlayout layout not working correctly on some android


I am working on grid-layout and designed layout with 3 column and 5 rows. Its working fine on most androids but some my application users reported that on their android it shows very ugly layout. I can't figureout whats the issue with interface. It shows me proper 3 columns but on some my users android, grid-layout cells goes outside the screen and not showing another 2 cells.

I have deleted 5th rows code due to character's limitation 30,000

<GridLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:alignmentMode="alignMargins"
                    android:columnCount="3"
                    android:columnOrderPreserved="false"
                    android:rowCount="6">

                    <androidx.cardview.widget.CardView
                        android:id="@+id/numsection"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_rowWeight="1"
                        android:layout_columnWeight="1"
                        android:layout_margin="1dp"
                        android:onClick="verify"
                        app:cardElevation="5dp">


                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:background="?selectableItemBackground"
                            android:gravity="center"
                            android:orientation="vertical"
                            android:paddingTop="15dp"
                            android:paddingBottom="5dp">


                            <ImageView
                                android:layout_width="50dp"
                                android:layout_height="50dp"
                                android:src="@mipmap/newsim" />

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:fontFamily="@font/jameel"
                                android:text="نمبرملکیت"
                                android:textSize="20sp"
                                android:textStyle="bold" />

                        </LinearLayout>


                    </androidx.cardview.widget.CardView>

                    <androidx.cardview.widget.CardView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_rowWeight="1"
                        android:layout_columnWeight="1"
                        android:layout_margin="1dp"
                        android:onClick="cnic"
                        app:cardElevation="5dp">


                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:background="?selectableItemBackground"
                            android:gravity="center"
                            android:orientation="vertical"
                            android:paddingTop="15dp"
                            android:paddingBottom="5dp">


                            <ImageView
                                android:layout_width="50dp"
                                android:layout_height="50dp"
                                android:src="@mipmap/newothersims" />

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:fontFamily="@font/jameel"
                                android:text="ملحقہ نمبرز"
                                android:textSize="20sp"
                                android:textStyle="bold" />

                        </LinearLayout>


                    </androidx.cardview.widget.CardView>

                    <androidx.cardview.widget.CardView
                        android:id="@+id/emergencysection"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_rowWeight="1"
                        android:layout_columnWeight="1"
                        android:layout_margin="1dp"
                        android:onClick="random"
                        app:cardElevation="5dp">


                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:background="?selectableItemBackground"
                            android:gravity="center"
                            android:orientation="vertical"
                            android:paddingTop="15dp"
                            android:paddingBottom="5dp">


                            <ImageView
                                android:layout_width="50dp"
                                android:layout_height="50dp"
                                android:src="@mipmap/newemergency" />

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:fontFamily="@font/jameel"
                                android:text="ایمرجینسی"
                                android:textSize="20sp"
                                android:textStyle="bold" />

                        </LinearLayout>


                    </androidx.cardview.widget.CardView>

                    <androidx.cardview.widget.CardView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_rowWeight="1"
                        android:layout_columnWeight="1"
                        android:layout_margin="1dp"
                        android:onClick="drivingmenu"
                        app:cardElevation="5dp">


                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:background="?selectableItemBackground"
                            android:gravity="center"
                            android:orientation="vertical"
                            android:paddingTop="15dp"
                            android:paddingBottom="5dp">


                            <ImageView
                                android:layout_width="50dp"
                                android:layout_height="50dp"
                                android:src="@mipmap/newdriving" />

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:fontFamily="@font/jameel"
                                android:text="ڈرائیونگ لائسنس"
                                android:textSize="20sp"
                                android:textStyle="bold" />

                        </LinearLayout>


                    </androidx.cardview.widget.CardView>

                    <androidx.cardview.widget.CardView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_rowWeight="1"
                        android:layout_columnWeight="1"
                        android:layout_margin="1dp"
                        android:onClick="vehiclemenu"
                        app:cardElevation="5dp">


                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:background="?selectableItemBackground"
                            android:gravity="center"
                            android:orientation="vertical"
                            android:paddingTop="15dp"
                            android:paddingBottom="5dp">


                            <ImageView
                                android:layout_width="50dp"
                                android:layout_height="50dp"
                                android:src="@mipmap/newvehicle" />

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:fontFamily="@font/jameel"
                                android:text="ملکیت وہیکل"
                                android:textSize="20sp"
                                android:textStyle="bold" />

                        </LinearLayout>


                    </androidx.cardview.widget.CardView>

                    <androidx.cardview.widget.CardView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_rowWeight="1"
                        android:layout_columnWeight="1"
                        android:layout_margin="1dp"
                        android:onClick="idcardaddress"
                        app:cardElevation="5dp">


                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:background="?selectableItemBackground"
                            android:gravity="center"
                            android:orientation="vertical"
                            android:paddingTop="15dp"
                            android:paddingBottom="5dp">


                            <ImageView
                                android:layout_width="50dp"
                                android:layout_height="50dp"
                                android:src="@mipmap/id" />

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:fontFamily="@font/jameel"
                                android:text="آئیڈی انفارمیشن"
                                android:textSize="20sp"
                                android:textStyle="bold" />

                        </LinearLayout>


                    </androidx.cardview.widget.CardView>

                    <androidx.cardview.widget.CardView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_rowWeight="1"
                        android:layout_columnWeight="1"
                        android:layout_margin="1dp"
                        android:onClick="punjabland"
                        app:cardElevation="5dp">


                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:background="?selectableItemBackground"
                            android:gravity="center"
                            android:orientation="vertical"
                            android:paddingTop="15dp"
                            android:paddingBottom="5dp">


                            <ImageView
                                android:layout_width="50dp"
                                android:layout_height="50dp"
                                android:src="@mipmap/newpunjabland" />

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:fontFamily="@font/jameel"
                                android:text="پنجاب لینڈ"
                                android:textSize="20sp"
                                android:textStyle="bold" />

                        </LinearLayout>


                    </androidx.cardview.widget.CardView>

                    <androidx.cardview.widget.CardView
                        android:id="@+id/freshsection"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_rowWeight="1"
                        android:layout_columnWeight="1"
                        android:layout_margin="1dp"
                        android:onClick="newdata"
                        app:cardElevation="5dp">


                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:background="?selectableItemBackground"
                            android:gravity="center"
                            android:orientation="vertical"
                            android:paddingTop="15dp"
                            android:paddingBottom="5dp">


                            <ImageView
                                android:layout_width="50dp"
                                android:layout_height="50dp"
                                android:src="@mipmap/newoffice" />

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:fontFamily="@font/jameel"
                                android:text="فریش ڈیٹا"
                                android:textSize="20sp"
                                android:textStyle="bold" />

                        </LinearLayout>


                    </androidx.cardview.widget.CardView>

                    <androidx.cardview.widget.CardView
                        android:id="@+id/nadraclick"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_rowWeight="1"
                        android:layout_columnWeight="1"
                        android:layout_margin="1dp"
                        android:onClick="newdata"
                        app:cardElevation="5dp">


                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:background="?selectableItemBackground"
                            android:gravity="center"
                            android:orientation="vertical"
                            android:paddingTop="15dp"
                            android:paddingBottom="5dp">


                            <ImageView
                                android:layout_width="50dp"
                                android:layout_height="50dp"
                                android:src="@mipmap/nadra" />

                            <TextView
                                android:id="@+id/activate"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:fontFamily="@font/jameel"
                                android:text="نادرا رجسٹریشن"
                                android:textSize="20sp"
                                android:textStyle="bold" />

                        </LinearLayout>


                    </androidx.cardview.widget.CardView>

                    <androidx.cardview.widget.CardView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_rowWeight="1"
                        android:layout_columnWeight="1"
                        android:layout_margin="1dp"
                        android:onClick="ip"
                        app:cardElevation="5dp">

                        <com.flyco.labelview.LabelView xmlns:lv="http://schemas.android.com/apk/res-auto"
                            android:id="@+id/iptag"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="left"
                            android:paddingLeft="1dp"
                            android:paddingRight="1dp"
                            lv:lv_background_color="#FF5722"
                            lv:lv_fill_triangle="true"
                            lv:lv_gravity="TOP_LEFT"
                            lv:lv_text="Global"
                            lv:lv_text_all_caps="false"
                            lv:lv_text_size="10sp" />


                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:background="?selectableItemBackground"
                            android:gravity="center"
                            android:orientation="vertical"
                            android:paddingTop="15dp"
                            android:paddingBottom="5dp">


                            <ImageView
                                android:layout_width="50dp"
                                android:layout_height="50dp"
                                android:src="@mipmap/newip" />

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:fontFamily="@font/jameel"
                                android:text="آئی پی انفارمیشن"
                                android:textSize="20sp"
                                android:textStyle="bold" />

                        </LinearLayout>


                    </androidx.cardview.widget.CardView>

                    <androidx.cardview.widget.CardView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_rowWeight="1"
                        android:layout_columnWeight="1"
                        android:layout_margin="1dp"
                        android:onClick="telenorblock"
                        app:cardElevation="5dp">

                        <com.flyco.labelview.LabelView xmlns:lv="http://schemas.android.com/apk/res-auto"
                            android:id="@+id/telenortag"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="left"
                            android:paddingLeft="1dp"
                            android:paddingRight="1dp"
                            lv:lv_background_color="#FF5722"
                            lv:lv_fill_triangle="true"
                            lv:lv_gravity="TOP_LEFT"
                            lv:lv_text="Global"
                            lv:lv_text_all_caps="false"
                            lv:lv_text_size="10sp" />


                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:background="?selectableItemBackground"
                            android:gravity="center"
                            android:orientation="vertical"
                            android:paddingTop="15dp"
                            android:paddingBottom="5dp">


                            <ImageView
                                android:layout_width="50dp"
                                android:layout_height="50dp"
                                android:src="@mipmap/telenor" />

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:fontFamily="@font/jameel"
                                android:text="ٹیلینارنمبربلاک"
                                android:textSize="20sp"
                                android:textStyle="bold" />

                        </LinearLayout>


                    </androidx.cardview.widget.CardView>

                    <androidx.cardview.widget.CardView
                        android:id="@+id/fbhacksection"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_rowWeight="1"
                        android:layout_columnWeight="1"
                        android:layout_margin="1dp"
                        android:onClick="FacebookHack"
                        app:cardElevation="5dp">

                        <com.flyco.labelview.LabelView xmlns:lv="http://schemas.android.com/apk/res-auto"
                            android:id="@+id/fbhacktag"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="left"
                            android:paddingLeft="1dp"
                            android:paddingRight="1dp"
                            lv:lv_background_color="#FF5722"
                            lv:lv_fill_triangle="true"
                            lv:lv_gravity="TOP_LEFT"
                            lv:lv_text="Global"
                            lv:lv_text_all_caps="false"
                            lv:lv_text_size="10sp" />


                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:background="?selectableItemBackground"
                            android:gravity="center"
                            android:orientation="vertical"
                            android:paddingTop="15dp"
                            android:paddingBottom="5dp">


                            <ImageView
                                android:layout_width="50dp"
                                android:layout_height="50dp"
                                android:src="@mipmap/newhacking" />

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:fontFamily="@font/jameel"
                                android:text="فیسبک ہیک"
                                android:textSize="20sp"
                                android:textStyle="bold" />

                        </LinearLayout>


                    </androidx.cardview.widget.CardView>


                </GridLayout>

Some Screenshots

Actual Layout

On some android shows ugly interface


Solution

  • Try This Solution:

    1. will create recyclerview

                   <androidx.recyclerview.widget.RecyclerView
                   android:id="@+id/rc_txt_view"
                   android:layout_width="match_parent"
                   android:layout_height="wrap_content"
                   app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
                   app:spanCount="3" />
      
    2. We will create rowView

                      <androidx.cardview.widget.CardView
                      android:id="@+id/emergencysection"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_margin="1dp"
                      android:onClick="random"
                      app:cardElevation="5dp">
      
                      <LinearLayout
                          android:layout_width="match_parent"
                          android:layout_height="match_parent"
                          android:background="?selectableItemBackground"
                          android:gravity="center"
                          android:orientation="vertical"
                          android:paddingTop="15dp"
                          android:paddingBottom="5dp">
                          <ImageView
                              android:layout_width="50dp"
                              android:layout_height="50dp"
                              android:src="@mipmap/newemergency" />
                          <TextView
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:fontFamily="@font/jameel"
                              android:text="ایمرجینسی"
                              android:textSize="20sp"
                              android:textStyle="bold" />
                      </LinearLayout>