I am making a really simple app (basically a listview with only a few images). It generally performs really well on my testing device (a Motorola Moto G with the stock android that comes with it).
However, I want my ListView to have dotted dividers. Therefore I made a list_divider.xml file defining the divider and set this to be the divider to be used in the ListView. I have tried that out on my Moto G, but it didn't display the line dotted.
So I've googled around and found here a solution to the problem. Disabling hw acceleration for the view solved the error and displayed the divider correctly.
However, now I have another problem: Since disabling hw acceleration the app began to lag when scrolling.
Is there a solution to having a dotted divider and not disabling hw acceleration or at least have the performance nearly as good as before disabling it?
Edit: Here is the adapter code I use:
public class AstronautArrayAdapter extends ArrayAdapter<Astronaut> {
public static final String TAG = "AstronautArrayAdapter";
public AstronautArrayAdapter(Context context, List<Astronaut> objects) {
super(context, R.layout.astronauts_list_row, objects);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
RowViewHolder holder = null;
if (convertView == null) {
LayoutInflater inflater = ((Activity) getContext()).getLayoutInflater();
convertView = inflater.inflate(R.layout.astronauts_list_row, parent, false);
holder = new RowViewHolder();
holder.name = (TextView) convertView.findViewById(R.id.nameOfAustronaut);
holder.daysInSpace = (TextView) convertView.findViewById(R.id.numberOfDaysInSpace);
holder.country = (ImageView) convertView.findViewById(R.id.countryImage);
holder.title = (TextView) convertView.findViewById(R.id.titleOfAstronaut);
convertView.setTag(holder);
} else {
holder = (RowViewHolder) convertView.getTag();
}
Astronaut astronaut = getItem(position);
holder.name.setText(astronaut.getName());
holder.daysInSpace.setText(Integer.toString(astronaut.getDaysInSpace()));
holder.country.setImageBitmap(astronaut.getCountryImage(getContext()));
holder.title.setText(astronaut.getTitle());
return convertView;
}
private static class RowViewHolder {
TextView name;
TextView daysInSpace;
ImageView country;
TextView title;
}
}
Edit 2: Here are the two layout files in question:
activity_main.xml
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/astronautsList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="16dp"
android:dividerHeight="3dp"
android:divider="@drawable/list_divider"
android:layerType="software" />
list_divider.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line" >
<stroke
android:width="1px"
android:color="@android:color/black"
android:dashWidth="5px"
android:dashGap="1px" />
<size android:height="3dp" />
</shape>
possible answer for the lag you're seeing is:
add this line inside the dependencies section to your build.gradle
compile 'com.squareup.picasso:picasso:2.3.2'
and replace this line
holder.country.setImageBitmap(astronaut.getCountryImage(getContext()));
with
Picasso.with(context).load(/* insert the URL here */).into(holder.country);
and remove the code that is downloading all the images and saving locally. Picasso automagically download/decode the bitmaps and manage disk and ram cache for you.
ps.:
if you're not using Gradle:
libs folder and make sure to mess on the project settings to make sure that jar goes inside your APK (I honestly do not remember how those settings work because I abandoned Eclipse long time ago)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With