Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 背景图像降低了recyclerview性能_Java_Android_Android Recyclerview_Imageview - Fatal编程技术网

Java 背景图像降低了recyclerview性能

Java 背景图像降低了recyclerview性能,java,android,android-recyclerview,imageview,Java,Android,Android Recyclerview,Imageview,我有一个包含背景图像视图和回收器视图的应用程序。当我将fitxy缩放到背景图像回收器视图时,滚动速度减慢。当我删除bg图像缩放时,滚动性能很快。但我不能使用没有缩放xy的图像视图,因为即使我的图像大小与屏幕大小相同,也无法填充整个屏幕。我的图像在设备存储器中。我将图像读取为位图,并设置图像组件位图 编辑:我忘记了一个要点,安卓5或5+版本的性能比安卓4好。但是安卓5比4更好的回收器视图滚动仍然不平滑。 我尝试将Glide图像加载到imageview,但结果性能仍然很慢。图像加载代码为: F

我有一个包含背景图像视图和回收器视图的应用程序。当我将fitxy缩放到背景图像回收器视图时,滚动速度减慢。当我删除bg图像缩放时,滚动性能很快。但我不能使用没有缩放xy的图像视图,因为即使我的图像大小与屏幕大小相同,也无法填充整个屏幕。我的图像在设备存储器中。我将图像读取为位图,并设置图像组件位图

编辑:我忘记了一个要点,安卓5或5+版本的性能比安卓4好。但是安卓5比4更好的回收器视图滚动仍然不平滑。
我尝试将Glide图像加载到imageview,但结果性能仍然很慢。图像加载代码为:

   File f = new File(Constants.SETTINGS_MEDIA_LOCAL_FOLDER, 
   ApplicationManager.ShopSet.getMenuPageBackImage());
        Glide.with(ProductListActivity.this).load(Constants.FOLDERS_PREFIX + 
        f.getPath()).into(iv`enter code here`CategoryBg);
我的布局xml是:

    <RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
   android:layout_height="match_parent">
    <ImageView
    android:id="@+id/ivProductListBg"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="fitXY"
   />

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

    <LinearLayout
        android:id="@+id/llCategoryHeader"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_alignParentTop="true"
        android:layout_weight=".5"
        android:orientation="vertical">

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:orientation="horizontal">

            <LinearLayout
                android:id="@+id/llBackButtonProductList"
                android:layout_width="130dp"
                android:layout_height="56dp"
                android:layout_alignParentLeft="true"
                android:layout_marginTop="30dp"
                android:clickable="true"
                android:orientation="horizontal">


                <TextView
                    android:id="@+id/tvBackButtonProductList"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_weight="2"
                    android:padding="5dp"
                    android:text="Back"
                    android:textAlignment="center"
                    android:textColor="@color/colorWhite"
                    android:textSize="24dp" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="280dp"
                android:layout_height="120dp"
                android:layout_centerInParent="true"
                android:orientation="horizontal">

                <ImageView
                    android:id="@+id/ivProductListLogo"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/llCartButtonProductList"
                android:layout_width="130dp"
                android:layout_height="56dp"
                android:layout_alignParentRight="true"
                android:layout_marginTop="30dp"
                android:orientation="horizontal">

                <TextView
                    android:id="@+id/tvCartButtonProductList"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_weight="2"
                    android:padding="5dp"
                    android:text="0,00"
                    android:textAlignment="center"
                    android:textColor="@color/colorWhite"
                    android:textSize="24dp" />
            </LinearLayout>

        </RelativeLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_below="@+id/llProductListHeader"
        android:layout_weight=".25"
        android:orientation="vertical">

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

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="5">

                <TextView
                    android:id="@+id/tvProductListCategoryName"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="center_vertical"
                    android:paddingLeft="25dp"
                    android:text="METE"
                    android:textColor="@color/black"
                    android:textSize="28dp"
                    android:textStyle="bold" />


            </LinearLayout>


            <LinearLayout
                android:id="@+id/llProductListViewChoose"
                android:layout_width="150dp"
                android:layout_height="30dp"
                android:layout_alignParentRight="true"
                android:layout_gravity="bottom"
                android:layout_marginRight="5dp"
                android:layout_marginBottom="10dp"
                android:background="@drawable/border"
                android:orientation="horizontal"
                android:visibility="invisible">

                <LinearLayout
                    android:id="@+id/llProductListSingleViewChoose"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_margin="1dp"
                    android:layout_weight="1"
                    android:gravity="center">

                    <ImageView
                        android:id="@+id/ivProductListSingleView"
                        android:layout_width="46dp"
                        android:layout_height="28dp"
                        android:layout_gravity="center"
                        android:scaleType="center"
                        android:src="@drawable/singleviewbutton" />
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/llProductListDoubleViewChoose"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_margin="1dp"
                    android:layout_weight="1"
                    android:gravity="center">

                    <ImageView
                        android:id="@+id/ivProductListDoubleView"
                        android:layout_width="46dp"
                        android:layout_height="28dp"
                        android:layout_gravity="center"
                        android:scaleType="centerInside"
                        android:src="@drawable/doubleviewbutton" />
                </LinearLayout>


            </LinearLayout>

        </LinearLayout>


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_below="@+id/llProductListHeader2"
        android:layout_weight=".25"
        android:orientation="vertical">

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

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="3">

                <TextView
                    android:id="@+id/tvProductListCategoryInfo"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="center_vertical"
                    android:paddingLeft="25dp"
                    android:text="METE"
                    android:textColor="@color/black"
                    android:textSize="21dp" />

            </LinearLayout>


        </LinearLayout>

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_below="@+id/llProductListHeader2"
        android:layout_weight=".30"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="150dp"
            android:layout_height="match_parent"
            android:layout_gravity="right"
            android:visibility="invisible">

            <View
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="1" />

            <ImageView
                android:id="@+id/img_LanguageProductList"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:layout_marginRight="5dp"
                android:scaleType="fitXY"
                android:src="@drawable/language" />
        </LinearLayout>


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_below="@+id/llCategoryList"
        android:layout_weight="4"
        android:orientation="vertical"
        android:paddingLeft="5dp"
        android:paddingRight="5dp">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerviewProductList"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:visibility="visible">

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

        <ListView
            android:id="@+id/listviewProductList"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:scrollingCache="false"></ListView>


    </LinearLayout>


</LinearLayout>


ivProductListBg是我的bg图像视图。如果我删除ivProductListBg android:scaleType=“fitXY”属性,则使用相同的代码一切正常,但当我添加android:scaleType=“fitXY”属性时,recyclerview滚动速度变慢。

我猜这可能是您使用的图像大小的问题。确保它不是一个很重的文件


您可以尝试压缩它或调整它的大小。

请检查以下内容:

有几个库遵循加载图像的最佳实践。您可以在应用程序中使用这些库以最优化的方式加载图像。我们推荐Glide库,它可以尽可能快速、流畅地加载和显示图像。其他流行的图像加载库包括来自Square的毕加索和来自Facebook的Fresco。这些库简化了Android上与位图和其他类型图像相关的大多数复杂任务


您好,欢迎来到苏。请向我们展示所有相关代码。生成位图需要时间,请尝试使用Glide/Picasso等图像显示库。请发布一些代码以确定任何问题。压缩图像会增加解压缩时的开销。