Android ScrollView在与多个ImageViews一起使用时滞后(渲染问题)



我正在尝试为我的应用程序创建一个简单的主页。然而,当我试图滚动页面时,我的主页出现了性能问题。你能告诉我我做错了什么吗?或者我能做得更好吗?(我的图像大小平均约为100kb。(我尝试过最小化图像的大小,使用回收器视图,减少我使用的LinearLayouts的数量,使用ConstraintLayout而不是LinearLayout,但这些都不适用于我。谢谢你的帮助!

这是我主页的截图:我的主页截图链接

这是我的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="#F6F0E2"
tools:context=".HomeActivity">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/nameTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:text="Bilgiler alınamadı"
android:textColor="@color/black"
android:textSize="17sp"
android:textStyle="italic" />

<!-- SİPARİŞ VE BİLGİLER -->
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="#ffffff"
android:orientation="vertical">

<!-- TİTLE -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:text="SİPARİŞ VE BİLGİLER"
android:textColor="#5c5c5c"
android:textSize="13sp"
android:textStyle="bold" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- CHECK-IN -->
<TableRow>
<ImageView
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp"
android:padding="4dp"
android:src="@drawable/check" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="22dp"
android:text="Check-In"
android:textColor="@color/black"
android:textSize="12sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="2dp"
android:text="QR Kod Okut"
android:textColor="#949494"
android:textSize="12sp" />
</LinearLayout>
</TableRow>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="#c0c0c0" />
<!-- MENÜ -->
<TableRow>
<ImageView
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_marginStart="15dp"
android:padding="4dp"
android:src="@drawable/menu" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="7dp"
android:text="Menü"
android:textColor="@color/black"
android:textSize="12sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="2dp"
android:text="Görmek için tıklayınız"
android:textColor="#949494"
android:textSize="12sp" />
</LinearLayout>
</TableRow>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="#c0c0c0" />
<!-- SİPARİŞLER -->
<TableRow>
<ImageView
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_marginStart="15dp"
android:padding="4dp"
android:src="@drawable/siparisler" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="7dp"
android:text="Siparişler"
android:textColor="@color/black"
android:textSize="12sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="2dp"
android:text="Siparişlerinize göz atın"
android:textColor="#949494"
android:textSize="12sp" />
</LinearLayout>
</TableRow>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="#c0c0c0" />
<!-- WC -->
<TableRow>
<ImageView
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_marginLeft="15dp"
android:padding="4dp"
android:src="@drawable/wc" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="7dp"
android:text="WC Bay - AQQQQ"
android:textColor="@color/black"
android:textSize="12dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="2dp"
android:text="WC Bayan - AQQQQQ"
android:textColor="@color/black"
android:textSize="12dp" />
</LinearLayout>
</TableRow>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="#c0c0c0" />
<!-- RESTORAN -->
<TableRow android:layout_marginBottom="10dp">
<ImageView
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_marginLeft="15dp"
android:padding="4dp"
android:src="@drawable/rest" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="7dp"
android:text="Restoran - AQQQQ"
android:textColor="@color/black"
android:textSize="12sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="2dp"
android:text="Sıra Al - Ort: 31 dk"
android:textColor="#949494"
android:textSize="12sp" />
</LinearLayout>
</TableRow>
</TableLayout>
</androidx.cardview.widget.CardView>
<!-- ÇAĞRI VE YARDIM -->
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="#ffffff">
<!-- TİTLE -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:text="ÇAĞRI VE YARDIM"
android:textColor="#5c5c5c"
android:textSize="13sp"
android:textStyle="bold" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- GARSON ÇAĞIR -->
<TableRow>
<ImageView
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp"
android:padding="4dp"
android:src="@drawable/waiter" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="22dp"
android:text="Garson Çağır"
android:textColor="@color/black"
android:textSize="12sp" />
</LinearLayout>
</TableRow>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="#c0c0c0" />
<!-- HESAP İSTE -->
<TableRow>
<ImageView
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_marginStart="15dp"
android:padding="4dp"
android:src="@drawable/wallet" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="7dp"
android:text="Hesap İste"
android:textColor="@color/black"
android:textSize="12sp" />
</LinearLayout>
</TableRow>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="#c0c0c0" />
<!-- HALKLA İLİŞKİLER -->
<TableRow>
<ImageView
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_marginStart="15dp"
android:padding="4dp"
android:src="@drawable/hr" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="7dp"
android:text="Halkla İlişkiler"
android:textColor="@color/black"
android:textSize="12sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="2dp"
android:text="Yardım İste"
android:textColor="#949494"
android:textSize="12sp" />
</LinearLayout>
</TableRow>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="#c0c0c0" />
</TableLayout>
</androidx.cardview.widget.CardView>
<!-- ÇAĞRI VE YARDIM -->
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="#ffffff">
<!-- TİTLE -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:text="ÇAĞRI VE YARDIM"
android:textColor="#5c5c5c"
android:textSize="13sp"
android:textStyle="bold" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- GARSON ÇAĞIR -->
<TableRow>
<ImageView
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp"
android:padding="4dp"
android:src="@drawable/waiter" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="22dp"
android:text="Garson Çağır"
android:textColor="@color/black"
android:textSize="12sp" />
</LinearLayout>
</TableRow>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="#c0c0c0" />
<!-- HESAP İSTE -->
<TableRow>
<ImageView
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_marginStart="15dp"
android:padding="4dp"
android:src="@drawable/wallet" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="7dp"
android:text="Hesap İste"
android:textColor="@color/black"
android:textSize="12sp" />
</LinearLayout>
</TableRow>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="#c0c0c0" />
<!-- HALKLA İLİŞKİLER -->
<TableRow>
<ImageView
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_marginStart="15dp"
android:padding="4dp"
android:src="@drawable/hr" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="7dp"
android:text="Halkla İlişkiler"
android:textColor="@color/black"
android:textSize="12sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="2dp"
android:text="Yardım İste"
android:textColor="#949494"
android:textSize="12sp" />
</LinearLayout>
</TableRow>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="#c0c0c0" />
</TableLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</ScrollView>

尝试使用Recyclerview而不是Scrollview。这样你将使用更少的资源。因此,以这种方式编码,表中的每一行都将是Recyclerview中的一个元素。

最新更新