3

I have a ScrollView that has some image Views. However, the scrolling is very slow and I do not understand what is the reason for the bad performance. Is there anything to do to speed up the scrolling ? or what can cause this problem ?

`

 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView /> <ImageView /> <ImageView /> <ImageView /> <ImageView /> <ImageView /> </RelativeLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:gravity="center" android:orientation="vertical"> <Button /> </LinearLayout> </RelativeLayout> </ScrollView> </RelativeLayout>` 
1
  • Besides the unnecessarily nested RelativeLayout there doesn't seem to be anything that would cause an issue. By "slow" do you mean it literally scrolls slowly or do you mean choppy and maybe problems with rendering when scrolling? How big are those images you are loading? If you are loading big images, maybe try reducing their file sizes? Commented Apr 5, 2016 at 19:05

3 Answers 3

4

The problem was the size of the images. So if you have some performance issues with ScrollView and multiple ImageViews, pay attention to the size of your images! In my case I reduced them to approx. 20KB - 50KB each image.

Sign up to request clarification or add additional context in comments.

1 Comment

i have 20 of images with 17-25 KB each image. then why its lagging?
0

I'm not very fluent in english but i will try to explain it to you !

you just have to try to change you scrollview position like this

 **<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView /> <ImageView /> <ImageView /> <ImageView /> <ImageView /> <ImageView /> </RelativeLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:gravity="center" android:orientation="vertical"> <Button /> </LinearLayout> </RelativeLayout> </ScrollView> 

2 Comments

Thanks, I will try it.
Unfortunately it did not help.
0

The more child views within child views you have the more taxing on the system , I don't get why would you use a RelativeLayout inside a parent RelativeLayout. you only posted a snipet but I see that you have to many child layouts.

You find more here

it should look like this , or replace LinearLayout with RelativeLayout .

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" /> <ImageView android:layout_width="match_parent" android:layout_height="100dp" /> <ImageView android:layout_width="match_parent" android:layout_height="100dp" /> <ImageView android:layout_width="match_parent" android:layout_height="100dp" /> <ImageView android:layout_width="match_parent" android:layout_height="100dp" /> <Button android:layout_width="wrap_content" android:layout_height="100dp" /> </LinearLayout> 

3 Comments

Even If I remove all the RelativeLayouts, and I have just the ScrollView and inside one RelativeLayout it is still very slow.
why do you have them empty ImageView tags
I removed the code inside the ImageView just for the example.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.