Android: Optimize nested layouts -


i have created layout , i'm experiencing lot of performance issues in gridview. have read nested layouts can prevent smooth scrolling:

http://developer.android.com/training/improving-layouts/optimizing-layout.html

here code:

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="100dp"     android:layout_height="wrap_content">       <relativelayout         xmlns:android="http://schemas.android.com/apk/res/android"         android:id="@+id/relativelayout"         android:layout_width="wrap_content"         android:layout_height="wrap_content" >          <com.bestpick.bestpickapplication.squareimageview             android:id="@+id/menu_item_image"             android:layout_width="match_parent"             android:layout_height="100dp"             android:background="@color/lightgrey"             android:layout_alignparenttop="true"             android:layout_centerhorizontal="true"             />            <linearlayout             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_alignbottom="@+id/menu_item_image"             android:background="#77000000"             android:orientation="vertical">             <textview                 android:id="@+id/menu_item_name"                 android:layout_width="fill_parent"                 android:layout_height="wrap_content"                 android:layout_margin="1dp"                 android:textcolor="@color/white"                 android:gravity="left"                 android:text="title"                 android:textsize="12sp"                 android:maxlines="2"                 android:ellipsize="end"                 />             <linearlayout                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:orientation="horizontal"                 android:gravity="center_vertical">                  <ratingbar android:id="@+id/menu_item_avg_rating"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:numstars="5"                     android:stepsize="0.1"                     android:rating="0"                     style="?android:attr/ratingbarstylesmall"                     />                  <textview                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:textcolor="@color/white"                     android:text= "("                     android:textsize="12sp"/>                 <textview                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:id="@+id/menu_item_number_ratings"                     android:text= "0"                     android:textcolor="@color/white"                     android:textsize="12sp"/>                 <textview                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:text= ")"                     android:textcolor="@color/white"                     android:textsize="12sp"/>               </linearlayout>           </linearlayout>      </relativelayout>  </linearlayout> 

how can achieve same result without many levels of layouts?

edit: picture of layout picture of target layout

i left out superfluous things (e.g. text color, etc) can see how layout attributes used produce effect want. layout uses 6 views , 1 level of nesting -- if want minimize number of views, it's possible 5 views, cleaner approach.

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="100dp"     android:layout_height="100dp" >      <com.bestpick.bestpickapplication.squareimageview         android:id="@+id/menu_item_image"         android:layout_width="match_parent"         android:layout_height="match_parent" />      <view android:background="#77000000"         android:layout_width="match_parent"         android:layout_height="0dp"         android:layout_aligntop="@+id/menu_item_name"         android:layout_alignparentbottom="true"/>      <ratingbar         android:id="@+id/menu_item_avg_rating"         style="?android:attr/ratingbarstylesmall"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentbottom="true" />      <textview         android:id="@+id/menu_item_number_ratings"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentbottom="true"         android:layout_torightof="@id/menu_item_avg_rating" />      <textview         android:id="@+id/menu_item_name"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_above="@id/menu_item_avg_rating" />  </relativelayout> 

note textview next ratingbar, intention use string resource %1$d , use getstring(r.string.whatever, some_integer) appropriate text. see this link if don't know how works.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -