Как исправить медленный рендеринг в моем коде Android? - PullRequest
0 голосов
/ 19 декабря 2018

Мое приложение работает очень медленно, когда я прокручиваю вниз.Пожалуйста, помогите мне решить эту проблему.Я обеспокоен этим из-за того, что в таких статьях говорится, что Google Play может оштрафовать ваше приложение в рейтинге Play Store, если вы упадете в нижние 25%.

Все ресурсы проекта присутствуют по этому URL-адресу http://garudapixel.com/en/modern-dashboard-ui-design-android-studio-tutorial/

Я хочу сделать этот тип макета с прокруткой ...

Image Link

XML-код

<?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>

Основная деятельность

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);
}
}

1 Ответ

0 голосов
/ 19 декабря 2018

В моем случае я получил ту же проблему.Это было, изображения очень большие.Но в вашем случае вы также можете использовать recycle view с YourRecycleView.setLayoutManager(new GridLayoutManager(this,2)); в списке.Маленькие размеры изображений очень важны и для этого режима.Вы можете получить руководство, используя ссылку ниже.

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

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...