用大背景图像滚动视图时减少滞后

时间:2016-08-11 14:02:14

标签: android android-layout android-studio

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

这是我的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>

1 个答案:

答案 0 :(得分: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 with android:layout_width =&#34; 8000dp&#34;并绘制巨大的图像是罪魁祸首。