My app, particularly the MainActivity
suffers from some lag when I scroll through the RecyclerView
. I tried to fix OverDraw
as much as I can.
This is what my OverDraw
screenshot looks like:
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:background="@drawable/background"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".ChordsList.ChordsListActivity">
<RelativeLayout
android:id="@+id/layout_top"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/logo"
android:layout_width="match_parent"
android:layout_height="100dp"
android:scaleType="fitStart"
android:src="@drawable/icon_verde_acqua_tras"/>
<ImageButton
android:id="@+id/menu"
android:background="@color/trans"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/tasto_menu"
android:scaleType="fitCenter"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="20dp"
android:onClick="showMenu"/>
<ImageButton
android:id="@+id/search"
android:background="@color/trans"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/tasto_ricerca"
android:scaleType="fitCenter"
android:layout_centerVertical="true"
android:onClick="onSearchButtonPressed"
android:layout_toStartOf="@id/menu"
android:layout_marginTop="20dp" />
<ImageButton
android:id="@+id/tuner"
android:background="@color/trans"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:onClick="onTunerButtonPressed"
android:src="@drawable/tuner"
android:scaleType="fitCenter"
android:layout_toStartOf="@id/search"
android:layout_marginTop="20dp" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/chords_recycler"
android:layout_below="@+id/layout_top"
android:layout_alignParentStart="true"
android:layout_marginTop="25dp" />
</RelativeLayout>
row.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="wrap_content">
<TextView
android:id="@+id/nome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:layout_centerVertical="true"
android:textSize="25sp"
android:layout_marginTop="10dp"
android:fontFamily="sans-serif-condensed"
android:textStyle="bold"
android:textColor="@color/black" />
<ImageView
android:id="@+id/immagine_accordo"
android:layout_width="130dp"
android:layout_marginTop="5dp"
android:layout_height="100dp"
android:scaleType="fitCenter"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
Assuming that the problem is OverDraw (please tell me if it's not), how can I improve it further? I need everything that is in the Image, so I cannot remove the background.
As suggested by Ivanhoe, OverDraw does not seem to be a problem. The Adapter
class and binding could be.
Adapter class:
public class ChordsListAdapter extends RecyclerView.Adapter<ChordsListAdapter.MyViewHolder> {
private ArrayList<Accordo> chordsList;
Context c;
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView nome; //note
public ImageView immagine;
public MyViewHolder(View view) {
super(view);
nome = (TextView) view.findViewById(R.id.nome);
immagine = (ImageView) view.findViewById(R.id.immagine_accordo);
}
}
public ChordsListAdapter(Context c, ArrayList<Accordo> chordsList) {
this.chordsList = chordsList;
this.c = c;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.row, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
Accordo chord = chordsList.get(position);
holder.nome.setText(chord.getName());
holder.immagine.setImageResource(chord.getImage()[0]);
}
@Override
public int getItemCount() {
return chordsList.size();
}
}
Taking for granted that the problem is OverDraw
How do you know? \$\endgroup\$