【问题标题】:Lag in ScrollView with a lot of ImageButton在 ScrollView 中滞后很多 ImageButton
【发布时间】:2017-03-23 02:22:14
【问题描述】:

我是一名 Android 初学者,我正在构建一个有趣的 SoundBoard 应用程序,与 ScrollView 和很多(目前为 44 个ImageButton 并排在 2 列中。

这是它的样子:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

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

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="1dp"
        android:orientation="horizontal"
        android:weightSum="1">

        <ImageButton
            android:id="@+id/myImageButton1"
            android:tag="myTag1"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginRight="1dp"
            android:layout_weight=".5"
            android:adjustViewBounds="true"
            android:background="@null"
            android:clickable="true"
            android:foreground="?attr/selectableItemBackgroundBorderless"
            android:onClick="onSoundButtonClick"
            android:scaleType="fitXY"
            android:src="@drawable/myImage1" />

        <ImageButton
            android:id="@+id/myImageButton2"
            android:tag="myTag2"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight=".5"
            android:adjustViewBounds="true"
            android:background="@null"
            android:clickable="true"
            android:foreground="?attr/selectableItemBackgroundBorderless"
            android:onClick="onSoundButtonClick"
            android:scaleType="fitXY"
            android:src="@drawable/myImage2" />
    </LinearLayout>

   // More LinearLayout below for ImageButton side by side

</LinearLayout>

快速向下滚动时,我会遇到延迟。我尝试使用RecyclerView 构建应用程序,但它并没有解决问题(我可能误用了它)。 每个 .jpg 的重量在 20Ko 到 30Ko 之间,总共 1.24Mo,共 44 张图像。

你知道如何解决这个问题吗?

谢谢!

【问题讨论】:

  • 使用 Picasso 它是一个 Imageloader Lib,它会在需要时加载图像,以及它在后台线程上的工作,请查看此链接:simplifiedcoding.net/…
  • @ItzikSamara 我试过毕加索,它就像一个魅力!但是我找不到在一个项目上播放声音的方法......互联网上没有任何相关内容,你知道如何做吗?

标签: android scrollview imagebutton lag


【解决方案1】:

问题可能不在您的布局中。它在你的适配器上。你有一些good practices to apply by google,或者你可以对你的资源应用延迟加载,你可以在this topic找到。

这应该可以帮助您解决问题。

【讨论】:

    猜你喜欢
    • 2017-08-30
    • 1970-01-01
    • 1970-01-01
    • 2013-10-08
    • 1970-01-01
    • 2011-01-09
    • 2013-06-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多