Friday, 15 April 2011

Android ScrollView is extremely slow rendering imageviews -



Android ScrollView is extremely slow rendering imageviews -

i'm displaying multiple imageviews in layout added programmatically seems fine except scrollview itself... scrolls slow , lags alot while scrolling. can cause ?

<?xml version="1.0" encoding="utf-8"?> <scrollview xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <linearlayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:id="@+id/jobs_container" > </linearlayout> </scrollview>

edit: 've followed this , created listview successfully, yet 1 time again listview lags while scrolling. i'm getting imageview source webservice row item like:

public class rowitem { private string imagesrc; private string title; public rowitem(string src, string title) { this.imagesrc = src; this.title = title; } public string getimagesrc() { homecoming this.imagesrc; } public void setimagesrc(string src) { this.imagesrc = src; } public string gettitle() { homecoming this.title; } public void settitle(string title) { this.title = title; } }

i list of json objects, convert'em rowitem, utilize next code generate rows listview:

public view getview(int position, view convertview, viewgroup parent) { viewholder holder = null; rowitem rowitem = getitem(position); layoutinflater minflater = (layoutinflater) context .getsystemservice(activity.layout_inflater_service); if (convertview == null) { convertview = minflater.inflate(r.layout.list_item, null); holder = new viewholder(); holder.txttitle = (textview) convertview.findviewbyid(r.id.title); holder.imageview = (imageview) convertview.findviewbyid(r.id.icon); convertview.settag(holder); } else holder = (viewholder) convertview.gettag(); holder.txttitle.settext(rowitem.gettitle()); string url = rowitem.getimagesrc(); url = url.replace("~", domain); picasso.with(context).load(url).into(holder.imageview); homecoming convertview; }

and still lags bad.. idea?

update: think imageviews causing slow scrolling because before images downloaded , loaded everything's smooth after images loaded starts slow downwards , on every scroll hidden rows shown reload image again. reason?

instead of using scrollview , have utilize listview has scroll functionality , expands automatically items added

first step have define layout follows

<linearlayoutxmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <listview android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:id="@android:id/list" > </listview> </linearlayout>

implement custom listview adapter getview() method

view getview(int position, view convertview, viewgroup parent) { view v = convertview;

if(v == null) v = view.inflate(context , r.layout.your_item_layout_containing_image); imageview imageview = (imageview)v.findviewbyid(r.id.your_image_view_id); picasso.with(context).load(image_url).into(imageview); homecoming v;

}

picasso library yoou can download , utilize straight download images has features

android imageview scrollview android-linearlayout

No comments:

Post a Comment