Question

I am creating a activity for mix text and image input. Here is the xml for container.

<ScrollView
    android:id="@+id/new_question_body_scroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/new_question_tag_container"
    android:layout_above="@+id/oler_keyboard_accessory"
    android:layout_alignLeft="@+id/new_question_tag_container"
    android:layout_alignRight="@+id/new_question_tag_container"
    android:scrollbars="none">

    <LinearLayout
        android:id="@+id/new_question_body_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <EditText
            android:id="@+id/new_question_body_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@null"
            android:hint="Please edit your body here."
            android:layout_marginBottom="5dp"/>

    </LinearLayout>
</ScrollView>

After dynamically add three (not lag for two) imageViews, it become pretty lag when scrolling. Even if I make maxHeight and Width for each individual 50dp, the lag still exist. Am I adding imageView in the wrong way or this is the memory limit?

Was it helpful?

Solution

Wouldn't be better to use a ListView with custom layout (for each row) instead of a mix of ScrollView and LinearLayout?

If you want to add tons of images (just like a gallery), you may think about using LRUCache or another algorithm (i.e. lazy loading).

Also, consider the image size you're tring to load into memory. Maybe a smaller size and 'click to zoom' of each item should be a better aproach/UX

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top