0

My app is running very slow when I Scroll Down. Please help me fix this issue. I am concerned of this because of such articles that seem to say Google Play may penalize your app in the Play Store rankings if you fall in the bottom 25%.

All the project assets are present on this URL http://garudapixel.com/en/modern-dashboard-ui-design-android-studio-tutorial/

I want to make this type of layout in scrolling way...

Image Link

XML Code

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bgapps"
tools:context=".MainActivity">

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_marginTop="32dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/txtdashboard"
            android:text="My Dashboard"
            android:textColor="#FFFFFF"
            android:textSize="22sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:text="12 Items"
            android:layout_marginTop="6dp"
            android:layout_below="@+id/txtdashboard"
            android:textColor="#52BAFF"
            android:textSize="14sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <ImageView
            android:layout_alignParentEnd="true"
            android:src="@drawable/person"
            android:layout_width="62dp"
            android:layout_height="62dp" />

    </RelativeLayout>

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

        <android.support.v7.widget.CardView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            app:cardElevation="6dp"
            app:cardCornerRadius="12dp"
            android:layout_margin="12dp">

            <LinearLayout
                android:orientation="vertical"
                android:padding="16dp"
                android:gravity="center"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:src="@drawable/bookmark"
                    android:layout_width="80dp"
                    android:layout_height="80dp" />

                <TextView
                    android:layout_marginTop="12dp"
                    android:textColor="#6f6f6f"
                    android:textSize="18sp"
                    android:text="Calendar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

            </LinearLayout>

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            app:cardElevation="6dp"
            app:cardCornerRadius="12dp"
            android:layout_margin="12dp">

            <LinearLayout
                android:orientation="vertical"
                android:padding="16dp"
                android:gravity="center"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:src="@drawable/bookmark"
                    android:layout_width="80dp"
                    android:layout_height="80dp" />

                <TextView
                    android:layout_marginTop="12dp"
                    android:textColor="#6f6f6f"
                    android:textSize="18sp"
                    android:text="Calendar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

            </LinearLayout>

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            app:cardElevation="6dp"
            app:cardCornerRadius="12dp"
            android:layout_margin="12dp">

            <LinearLayout
                android:orientation="vertical"
                android:padding="16dp"
                android:gravity="center"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:src="@drawable/bookmark"
                    android:layout_width="80dp"
                    android:layout_height="80dp" />

                <TextView
                    android:layout_marginTop="12dp"
                    android:textColor="#6f6f6f"
                    android:textSize="18sp"
                    android:text="Calendar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

            </LinearLayout>

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            app:cardElevation="6dp"
            app:cardCornerRadius="12dp"
            android:layout_margin="12dp">

            <LinearLayout
                android:orientation="vertical"
                android:padding="16dp"
                android:gravity="center"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:src="@drawable/bookmark"
                    android:layout_width="80dp"
                    android:layout_height="80dp" />

                <TextView
                    android:layout_marginTop="12dp"
                    android:textColor="#6f6f6f"
                    android:textSize="18sp"
                    android:text="Calendar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

            </LinearLayout>

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            app:cardElevation="6dp"
            app:cardCornerRadius="12dp"
            android:layout_margin="12dp">

            <LinearLayout
                android:orientation="vertical"
                android:padding="16dp"
                android:gravity="center"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:src="@drawable/bookmark"
                    android:layout_width="80dp"
                    android:layout_height="80dp" />

                <TextView
                    android:layout_marginTop="12dp"
                    android:textColor="#6f6f6f"
                    android:textSize="18sp"
                    android:text="Calendar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

            </LinearLayout>

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            app:cardElevation="6dp"
            app:cardCornerRadius="12dp"
            android:layout_margin="12dp">

            <LinearLayout
                android:orientation="vertical"
                android:padding="16dp"
                android:gravity="center"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:src="@drawable/bookmark"
                    android:layout_width="80dp"
                    android:layout_height="80dp" />

                <TextView
                    android:layout_marginTop="12dp"
                    android:textColor="#6f6f6f"
                    android:textSize="18sp"
                    android:text="Calendar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

            </LinearLayout>

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            app:cardElevation="6dp"
            app:cardCornerRadius="12dp"
            android:layout_margin="12dp">

            <LinearLayout
                android:orientation="vertical"
                android:padding="16dp"
                android:gravity="center"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:src="@drawable/bookmark"
                    android:layout_width="80dp"
                    android:layout_height="80dp" />

                <TextView
                    android:layout_marginTop="12dp"
                    android:textColor="#6f6f6f"
                    android:textSize="18sp"
                    android:text="Calendar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

            </LinearLayout>

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            app:cardElevation="6dp"
            app:cardCornerRadius="12dp"
            android:layout_margin="12dp">

            <LinearLayout
                android:orientation="vertical"
                android:padding="16dp"
                android:gravity="center"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:src="@drawable/bookmark"
                    android:layout_width="80dp"
                    android:layout_height="80dp" />

                <TextView
                    android:layout_marginTop="12dp"
                    android:textColor="#6f6f6f"
                    android:textSize="18sp"
                    android:text="Calendar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

            </LinearLayout>

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            app:cardElevation="6dp"
            app:cardCornerRadius="12dp"
            android:layout_margin="12dp">

            <LinearLayout
                android:orientation="vertical"
                android:padding="16dp"
                android:gravity="center"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:src="@drawable/bookmark"
                    android:layout_width="80dp"
                    android:layout_height="80dp" />

                <TextView
                    android:layout_marginTop="12dp"
                    android:textColor="#6f6f6f"
                    android:textSize="18sp"
                    android:text="Calendar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

            </LinearLayout>

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            app:cardElevation="6dp"
            app:cardCornerRadius="12dp"
            android:layout_margin="12dp">

            <LinearLayout
                android:orientation="vertical"
                android:padding="16dp"
                android:gravity="center"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:src="@drawable/bookmark"
                    android:layout_width="80dp"
                    android:layout_height="80dp" />

                <TextView
                    android:layout_marginTop="12dp"
                    android:textColor="#6f6f6f"
                    android:textSize="18sp"
                    android:text="Calendar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

            </LinearLayout>

        </android.support.v7.widget.CardView>

    </GridLayout>
</LinearLayout>
</ScrollView>

Main Activity

package voidgoel.currentaffairs;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}
}
Jaymin
  • 2,879
  • 3
  • 19
  • 35
  • Hmm, that is pretty strange. Are the images very large? One option might be to try and use a ListView with an Adapter, but that still doesn't explain why this is so slow. – Zee Dec 19 '18 at 11:00
  • Use RecyclerView with grid layout manager https://stackoverflow.com/a/40587169/6772096 – Gokul Gowda Dec 19 '18 at 11:01
  • Use recyclerview and constraint layout instead nesting linear and relative layouts. – TheKarlo95 Dec 19 '18 at 12:12
  • Thanks @Zee For the help, Images are very large and now i reduced the size and it is working fyn..Many Thanks for your help – Sanchit Goel Dec 19 '18 at 19:58

1 Answers1

0

In my case I got the same problem. It was, images are very large. But your case you can also use recycle view with YourRecycleView.setLayoutManager(new GridLayoutManager(this,2)); within list. Images sizes are small is very important for that mode also. You can get some guide using below link.

https://www.journaldev.com/13792/android-gridlayoutmanager-example

vimukthi
  • 263
  • 3
  • 9
  • 1
    Thanks For the help, Images are very large and now i reduced the size and it is working fyn..Many Thanks for your help. – Sanchit Goel Dec 19 '18 at 19:58