Android: AdapterView lags when dynamically adding view to LinearLayout -


i'm creating music player application. music library activity viewpager 4 pages/fragments (corresponding albums, artists, songs , playlists). 3 of fragments gridview's , last 1 listview (the songs fragment). when application first started runs smoothly. however, when user selects song play (for first time) linearlayout (called 'now playing bar') dynamically created @ bottom of screen information playing song. @ points of gridview's , listview begin lagging quite badly when scrolled. weirdly enough viewpager doesn't seem experience lag switching between fragment's seamless before. problem persists when user exits player , resumes (in case 'now playing bar' visible).

there rather confusing factor in this. when user selects album, artist or playlist library creates new activity listview containing songs said artist/album/playlist. 'now playing bar' added activity causes no slowdown whatsoever. leads me conclude problem related viewpager and/or fragment's in library activity.

i have been stumped , appreciate help.

here xml layout library activity:

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"     android:orientation="vertical" android:id="@id/library_view" > <include layout="@layout/sd_error"/> <android.support.v4.view.viewpager     android:id="@+id/view_pager"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:layout_weight="1.0"      /> <include layout="@layout/now_playing_bar"/> 

and here code used create 'now playing bar':

public static void updatenowplaying(activity a)  {     view nowplayingview = a.findviewbyid(r.id.now_playing_bar);      if (nowplayingview == null)                  return;      try      {                                         if (true && musicutils.sservice != null && musicutils.sservice.getaudioid() != -1)          {             imageview cover = (imageview) nowplayingview.findviewbyid(r.id.cover);             textview title = (textview) nowplayingview.findviewbyid(r.id.title);             textview artist = (textview) nowplayingview.findviewbyid(r.id.artist);              title.settext(musicutils.sservice.gettrackname());             string artistname = musicutils.sservice.getartistname();                              if (mediastore.unknown_string.equals(artistname))                  artistname = a.getstring(r.string.unknown_artist_name);              artist.settext(artistname);              cover.setimageuri(contenturis.withappendedid(                  sartworkuri, sservice.getalbumid()));              if (cover.getdrawable() == null)                 cover.setimageresource(r.drawable.no_album_cover);                                nowplayingview.setvisibility(view.visible);             nowplayingview.setonclicklistener(new view.onclicklistener()              {                 public void onclick(view v)                  {                     context c = v.getcontext();                     c.startactivity(new intent(c, playeractivity.class));                 }             });             return;         }     }      catch (remoteexception ex) {}     nowplayingview.setvisibility(view.gone); } 

ok, turns out reason lag because of had android:layout_height="match_parent" , android:layout_weight="1.0". apparently if setting weight such should use android:layout_height="0dp" better performance. have absolutely no idea why case fixed problem.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -