Android 在安卓系统中,如何在所有页面上使用更少的内存?

Android 在安卓系统中,如何在所有页面上使用更少的内存?,android,memory,Android,Memory,一页多幅图片的应用。此页面在内存不足的手机中不显示。如何在该手机中显示此页面。我想应该使用缓存,但不知道如何使用 <LinearLayout 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" androi

一页多幅图片的应用。此页面在内存不足的手机中不显示。如何在该手机中显示此页面。我想应该使用缓存,但不知道如何使用

<LinearLayout 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="@color/white"
    android:orientation="vertical"
    tools:context="com.example.rb.musalla.Goals_Activity">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/white"
            android:orientation="vertical"
            android:padding="@dimen/_10sdp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="@dimen/_150sdp">

                <ImageView
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="0.5"
                    android:src="@drawable/ideas" />

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="0.5"
                    android:orientation="vertical">

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:layout_weight="0.9"
                        android:gravity="center"
                        android:text="text 1" />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:layout_weight="0.1"
                        android:gravity="center"
                        android:text="time 1" />
                </LinearLayout>

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="@dimen/_150sdp">

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="0.5"
                    android:orientation="vertical">

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:layout_weight="0.9"
                        android:gravity="center"
                        android:text="text 2" />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:layout_weight="0.1"
                        android:gravity="center"
                        android:text="time 2" />
                </LinearLayout>

                <ImageView
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="0.5"
                    android:padding="@dimen/_20sdp"
                    android:src="@drawable/getting_land" />
            </LinearLayout>
      </ScrollView>
</LinearLayout>


此外,我住在伊朗,由于抵制美国,我不能使用网站(如developer.android.com)。请写下解决方案或使用网站对我的国家来说不成问题。

在android中,如果没有对图像进行二次采样,一个屏幕上的许多图像可能会导致内存问题。在小屏幕上显示大图像没有意义,因此,使用子采样缩小图像:

加载大位图的基本步骤包括:

  • 确定所需大小(根据已知大小或确定目标视图的大小)
  • 使用BitmapFactory类获取位图的大小(将BitmapFactory.Options中的inJustDecodeBounds设置为true)
  • 计算子采样值并将其传递给位图工厂。选项设置inSampleSize
  • 使用位图工厂加载缩小的位图

这里有更多详细信息:

您可以使用代理或VPN来访问Google官方文档。我有VPN(Psiphon),但工作不好,还没有显示站点@CopsonRoad使用美国、加拿大等地的IP地址。它应该能很好地工作。