Axonshi 123
Axonshi 123

Reputation: 123

Decrease Lag When Scrolling Throught Views With Large Background Images

Large background images within scroll views are apparently very laggy, I've tried compressing the images, but that doesn't seem to change anything. Is there any way to decrease the scrolling lag? Any answers are appreciated, thanks!

And here is my XML layout...

    <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>

Upvotes: 1

Views: 944

Answers (1)

savepopulation
savepopulation

Reputation: 11921

It's a bit hard to find your problem but here're a few tips which may help.

1- Try to use small images.

2- You can use a image library for reduce image size and manage view operation.

Here're a few image libraries:

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

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

https://github.com/bumptech/glide

http://frescolib.org

3- You can reduce your layout's depth. You include layouts. It may cause to increase depth of your layout. You can check the usage of merge tag.

Edit:

4- @pskink: RelativeLayout with android:layout_width="8000dp" and drawing huge image is a culprit.

Upvotes: 1

Related Questions