【问题标题】:Decrease Lag When Scrolling Throught Views With Large Background Images滚动浏览具有大背景图像的视图时减少延迟
【发布时间】:2016-08-12 14:07:50
【问题描述】:

滚动视图中的大背景图像显然非常滞后,我尝试压缩图像,但这似乎并没有改变任何东西。有什么办法可以减少滚动延迟?任何答案都非常感谢,谢谢!

这是我的 XML 布局...

    <HorizontalScrollView
    android:overScrollMode="never"
    android:id="@+id/day_switcher"
    android:scrollbars="none"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ScrollView
        android:overScrollMode="never"
        android:scrollbars="none"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

    <RelativeLayout
        android:id="@+id/day_holder"
        android:layout_width="8000dp"
        android:layout_height="wrap_content">

        <RelativeLayout // Has Large Background Image
            android:id="@+id/day_left"
            android:background="some_background"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <include
                layout="@layout/day_view_1" />
        </RelativeLayout>

        <RelativeLayout // Has Large Background Image
            android:layout_toRightOf="@id/day_left"
            android:background="some_background"
            android:id="@+id/day_mid"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <include
                layout="@layout/day_view_2" />
        </RelativeLayout>

        <RelativeLayout // Has Large Background Image
            android:id="@+id/day_right"
            android:background="some_background"
            android:layout_toRightOf="@id/day_mid"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <include
                layout="@layout/day_view_3" />
        </RelativeLayout>

    </RelativeLayout>

    </ScrollView>

</HorizontalScrollView>

【问题讨论】:

  • 首先:图片的分辨率是多少?
  • 尝试减少您的视图层次结构。太乱了
  • @BartekLipinski 我猜是 1080 乘以 3000
  • 你试过这个没有图片的xml吗?也许你的问题不是图片。
  • @invisbo 不,没有图像它可以正常工作。它也适用于 1 个背景图像,但不是全部 3 个

标签: android android-layout android-studio


【解决方案1】:

找到您的问题有点困难,但这里有一些提示可能会有所帮助。

1- 尝试使用小图片。

2- 您可以使用图像库来减小图像大小并管理视图操作。

这里有一些图片库:

https://github.com/nostra13/Android-Universal-Image-Loader

http://square.github.io/picasso/

https://github.com/bumptech/glide

http://frescolib.org

3- 您可以减少布局的深度。您包括布局。它可能会增加布局的深度。可以查看merge标签的使用情况。

编辑:

4- @pskink:RelativeLayout 与 android:layout_width="8000dp" 并绘制巨大的图像是罪魁祸首。

【讨论】:

  • #3 听起来是最好的答案。我的意思是他的应用程序已经有 4 层深度,甚至没有进入包含的布局。 4 层应接近最大总深度。而且我怀疑他包含的布局是否更好。
  • savepopulation,他的RelativeLayoutandroid:layout_width="8000dp" 和绘制巨大的图像是罪魁祸首,布局的深度只有一次影响很小(在初始测量/布局阶段),因为滚动时既不滚动onMeasure 也不滚动onLayout 被调用
  • @pskink 顺便说一下,我认为布局深度也会影响 findViewById 的性能。
  • 滚动时?谁在滚动时调用findViewById
  • 当然不滚动。只需为阅读这些 cmets 的人添加注释即可。 (也许滚动一个不使用持有人模式的列表视图:))
猜你喜欢
  • 2012-09-08
  • 1970-01-01
  • 1970-01-01
  • 2020-04-17
  • 1970-01-01
  • 2018-08-12
  • 2014-09-06
  • 1970-01-01
  • 2013-07-15
相关资源
最近更新 更多