使用其他API我不会有问题来显示ListView及其图像。但是在API 24上我无法做到。
<ImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/comment_image"
android:layout_width="64dp"
android:layout_height="64dp"
android:paddingLeft="3dp"
android:layout_marginTop="3dp"
android:layout_marginBottom="5dp"
android:layout_centerVertical="true"
android:src="@drawable/soccer_comment"
android:layout_gravity="center_vertical" />
此外,使用其他API(&lt; 24),在左侧:
android:src="@drawable/soccer_comment"
出现图像,API 24不会发生
我的ListViewComentarioAdapter.class
import android.app.Activity;
import android.app.Fragment;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.LayerDrawable;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import de.hdodenhof.circleimageview.CircleImageView;
public class ListViewComentariosAdapter extends ArrayAdapter<Comentario> {
private FragmentActivity activity;
private List<Comentario> comentarioList;
public ListViewComentariosAdapter(FragmentActivity context, int resource, List<Comentario> objects) {
super(context, resource, objects);
this.activity = context;
this.comentarioList = objects;
}
@Override
public Comentario getItem(int position) {
return comentarioList.get(position);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.formato_fila_lista_comentarios, parent, false);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
holder.ratingBar.getTag(position);
}
holder.ratingBar.setOnRatingBarChangeListener(onRatingChangedListener(holder, position));
holder.ratingBar.setTag(position);
holder.ratingBar.setRating(getItem(position).getRatingStar());
holder.comentario.setText(getItem(position).getComentario());
holder.nombreUsuario.setText(getItem(position).getNombre());
holder.fecha.setText(getItem(position).getFecha());
holder.imagenComentario.setImageResource(getItem(position).getImagen());
return convertView;
}
private RatingBar.OnRatingBarChangeListener onRatingChangedListener(final ViewHolder holder, final int position) {
return new RatingBar.OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float v, boolean b) {
Comentario item = getItem(position);
item.setRatingStar(v);
}
};
}
private static class ViewHolder {
private RatingBar ratingBar;
private TextView comentario;
private TextView nombreUsuario;
private TextView fecha;
private ImageView imagenComentario;
public ViewHolder(View view) {
ratingBar = (RatingBar) view.findViewById(R.id.ratingBarComplejo);
imagenComentario = (ImageView) view.findViewById(R.id.comment_image);
LayerDrawable stars = (LayerDrawable) ratingBar.getProgressDrawable();
stars.getDrawable(2).setColorFilter(Color.parseColor("#FFD700"), PorterDuff.Mode.SRC_ATOP);
comentario = (TextView) view.findViewById(R.id.lbl_comentario);
nombreUsuario = (TextView) view.findViewById(R.id.lbl_nombre);
fecha = (TextView) view.findViewById(R.id.lbl_fechaComentario);
}
}
}
row_format.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/style_listview"
android:orientation="horizontal">
<LinearLayout
android:orientation="vertical"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_width="wrap_content"
android:foreground="@drawable/style_listview"
android:layout_height="wrap_content">
<ImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/comment_image"
android:layout_width="64dp"
android:layout_height="64dp"
android:paddingLeft="3dp"
android:layout_marginTop="3dp"
android:layout_marginBottom="5dp"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_marginLeft="6dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_height="wrap_content">