我有一个列表视图,显示一些带有每行图像的数据。事实是,当我滚动列表视图时,它会冻结而不是平滑滚动。我的代码如下:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder viewHolder = null;
final int posicion = position;
final float latitud;
final float longitud;
final ParkingClass parkingItems = mListParkings.get(position);
if(convertView == null) {
LayoutInflater inflater = LayoutInflater.from(mContext);
convertView = inflater.inflate(R.layout.activity_listado_parking, null);
//configure view holder
viewHolder = new ViewHolder();
viewHolder.imgBtnBorrarItem = (ImageButton)convertView.findViewById(R.id.imgBtnBorrarItem);
viewHolder.imageButtonFotoHolder = (ImageButton)convertView.findViewById(R.id.fotoParking);
viewHolder.imgBtnNotasItem = (ImageButton)convertView.findViewById(R.id.imgBtnNotasItem);
viewHolder.imgBtnRuta = (ImageButton)convertView.findViewById(R.id.imgBtnRuta);
//viewHolder.path = parkingItems.getFoto();
convertView.setTag(viewHolder);
}
else {
viewHolder = (ViewHolder)convertView.getTag();
}
if (parkingItems.getFoto() != null)
{
if (parkingItems.getFoto() != "NF")
{
Bitmap bitmap;
bitmap = ImageHelper.decodeFile(parkingItems.getFoto());
viewHolder.imageButtonFotoHolder.setImageBitmap(bitmap);
}
else
{
viewHolder.imageButtonFotoHolder.setImageDrawable(mContext.getResources().getDrawable(R.drawable.no_photo_icon96));
viewHolder.imageButtonFotoHolder.setScaleType(ScaleType.FIT_XY);
}
}
TextView txtCiudad = (TextView)convertView.findViewById(R.id.txtCiudad);
txtCiudad.setText(parkingItems.getCiudad());
TextView txtCalle = (TextView)convertView.findViewById(R.id.txtCalle);
txtCalle.setText(parkingItems.getCalle());
TextView txtNum = (TextView)convertView.findViewById(R.id.txtFecha);
txtNum.setText(parkingItems.getFecha().toString());
if (parkingItems.getLatitud() != null)
latitud = parkingItems.getLatitud();
else
latitud = 0.0f;
if (parkingItems.getLongitud() != null)
longitud = parkingItems.getLongitud();
else
longitud = 0.0f;
return convertview;}
那么,我怎样才能顺利滚动?添加asyntask? asynctask我无法获得良好的表现。没有使用scrolllistener。如何实现顺利滚动的良好开发?
先谢谢你。
更新
我的布局xml如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/fotoLayout"
android:padding="6dip" >
<ImageButton
android:id="@+id/fotoParking"
android:background="@null"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:src="@drawable/ic_launcher"
android:gravity="left"
android:contentDescription="@string/imagen" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/fotoParking"
android:paddingLeft="5dp" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Fecha: "
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:text="Ciudad: "
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/textView2"
android:text="Calle: "
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/txtFecha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView1"
android:layout_toRightOf="@+id/textView1"
android:text="TextView" />
<TextView
android:id="@+id/txtCiudad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView2"
android:layout_toRightOf="@+id/textView2"
android:maxLines="1"
android:text="TextView" />
<TextView
android:id="@+id/txtCalle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView3"
android:layout_toRightOf="@+id/textView3"
android:maxLines="1"
android:text="TextView" />
</RelativeLayout>
答案 0 :(得分:1)
getview方法不应该在UI线程上执行任何繁重的进程以获得平滑可滚动的listview。
使用通用图片加载器 this来显示图片,而不是获取位图并显示GetView方法。