ListView滚动如此之慢

时间:2014-10-21 11:55:26

标签: android listview

我的ListView使用Horizo​​ntalListView滚动速度很慢

我试图将Horizo​​ntalListView作为其他ListView中的页脚实现

或作为标题和它的工作,但它太慢,它不能正常工作。

所以这是我的客户适配器

public class HorizntallMediaList extends
    ArrayAdapter<ItemsMediaSuggestion> {
String ImageURL;
Context context;
int table = 0;
List<ItemsMediaSuggestion> objects;

ItemsMediaSuggestion related;

public HorizntallMediaList(Context context, int textViewResourceId,
        List<ItemsMediaSuggestion> objects,
        int table) {
    super(context, textViewResourceId, objects);

    this.context = context;
    this.objects = objects;
    this.table = table;
}

viewHolder holder = new viewHolder();

private class viewHolder {

    private RelativeLayout relativeLayout;
    private ImageView userImage, addImage;
    private TextView userName;

}

@Override
public long getItemId(int position) {

    return super.getItemId(position);
}

@Override
public int getCount() {

    return super.getCount();
}

@Override
public ItemsMediaSuggestion getItem(int position) {

    return super.getItem(position);
}


@Override
public View getView(final int position, View convertView, ViewGroup parent) {

    try{
        related = getItem(position);
    } catch (IndexOutOfBoundsException e) {

    }

    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    if (convertView == null) {
        convertView = inflater.inflate(R.layout.items_wall_horizntal,
                parent, false);

        holder = new viewHolder();

        holder.relativeLayout = (RelativeLayout) convertView
                .findViewById(R.id.horRelative);
        holder.userImage = (ImageView) convertView
                .findViewById(R.id.HorUserImage);

        holder.userName = (TextView) convertView.findViewById(R.id.HorName);
        holder.addImage = (ImageView) convertView.findViewById(R.id.HorAdd);
        holder.addImage.setVisibility(View.GONE);
        convertView.setTag(holder);

    } else {

        holder = (viewHolder) convertView.getTag();
    }


    holder.relativeLayout
            .setBackgroundColor(GlobalConstants.ColorPicker_int);

    if (table == 5) {
         ImageURL    = GlobalConstants.server_file
                + table
                + "/m/"
                + related.getStorage()
                + "."
                + related.getStorageRand() + ".jpg";

        holder.userName.setText(PublicMethods.readable(related
                .getDescribtion()));


    } else if (table == 6) {

        if (related.getStorage().equals("0")) {
            holder.userName.setText(PublicMethods.readable(related
                    .getTitle()));

             ImageURL = "https://img.youtube.com/vi/"
                    + related.getStorageRand() + "/1" + ".jpg";


        } else {
             ImageURL = GlobalConstants.server_file
                    + table
                    + "/m/"
                    + related.getStorage()
                    + "."
                    + related.getStorageRand() + ".jpg";

            holder.userName.setText(PublicMethods.readable(related
                    .getTitle()));



        }
    } else {

         ImageURL = GlobalConstants.server_file
                + 5
                + "/m/"
                + related.getStorage()
                + "."
                + related.getStorageRand() + ".jpg";

        holder.userName.setText(PublicMethods.readable(related.getTitle()));


    }
    Picasso.with(context).load(ImageURL).fit().into(holder.userImage);

    return convertView;
}

}

这是项目Xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/background_with_shadow"
android:orientation="vertical" >

<RelativeLayout
    android:layout_width="200dp"
    android:layout_height="200dp" >

    <ImageView
        android:id="@+id/HorUserImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
         />

    <RelativeLayout
        android:id="@+id/horRelative"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true" >

        <TextView
            android:id="@+id/HorName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="5dp"
            android:layout_toLeftOf="@+id/HorAdd"
            android:gravity="right"
            android:maxLines="1"
            android:text="Name"
            android:textColor="@color/WhiteColor"
            android:textSize="18sp" />

        <ImageView
            android:id="@+id/HorAdd"
            android:layout_width="40dp"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:src="@drawable/plus" />
    </RelativeLayout>
</RelativeLayout>

ListView XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
    android:id="@+id/HorizntallLin"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:background="@android:color/transparent"
    android:orientation="vertical"
    android:visibility="visible" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="250dp" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginLeft="3dp"
            android:layout_marginRight="3dp"
            android:background="@drawable/background_with_shadow" >
        </RelativeLayout>

        <TextView
            android:id="@+id/HorizntallAdvertiseText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:paddingLeft="15dp"
            android:paddingRight="15dp"
            android:text="@string/relatedTopics_st"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textStyle="bold" />

        <utilityfunction.HorizontalListView
            android:id="@+id/HotrizantelListViewmedia"
            android:layout_width="fill_parent"
            android:layout_height="200dp"
            android:layout_below="@+id/HorizntallAdvertiseText"
            android:listSelector="@android:color/white"
            android:saveEnabled="true"
            android:smoothScrollbar="true" >
        </utilityfunction.HorizontalListView>
    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="3dp"
        android:layout_marginRight="3dp"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=" "
            android:visibility="invisible" />
    </LinearLayout>
</LinearLayout>

1 个答案:

答案 0 :(得分:0)

试试这个:

    <ListView
    ...
    android:smoothScrollbar="true"/>