Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ScrollView渲染图像视图的速度非常慢_Android_Imageview_Scrollview_Android Linearlayout - Fatal编程技术网

Android ScrollView渲染图像视图的速度非常慢

Android ScrollView渲染图像视图的速度非常慢,android,imageview,scrollview,android-linearlayout,Android,Imageview,Scrollview,Android Linearlayout,我在我的布局中显示了多个ImageView,它们是通过编程方式添加的,除了scrollview本身之外,一切似乎都很好。。。它的滚动速度非常慢,滚动时滞后很多。这是什么原因造成的 <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"

我在我的布局中显示了多个ImageView,它们是通过编程方式添加的,除了scrollview本身之外,一切似乎都很好。。。它的滚动速度非常慢,滚动时滞后很多。这是什么原因造成的

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:id="@+id/jobs_container"
        >

    </LinearLayout>
</ScrollView>
我基本上得到json对象列表,将它们转换为RowItem,然后使用以下代码为listview生成行:

public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;
    RowItem rowItem = getItem(position);

    LayoutInflater mInflater = (LayoutInflater) context
        .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.list_item, null);
        holder = new ViewHolder();
        holder.txtTitle = (TextView) convertView.findViewById(R.id.title);
        holder.imageView = (ImageView) convertView.findViewById(R.id.icon);
        convertView.setTag(holder);
    } else
        holder = (ViewHolder) convertView.getTag();
    holder.txtTitle.setText(rowItem.getTitle());
    String url = rowItem.getImageSrc();
    url = url.replace("~", DOMAIN);
    Picasso.with(context).load(url).into(holder.imageView);

    return convertView;
}
而且它仍然落后,真的很糟糕。。有什么想法吗


更新:我认为ImageView导致了缓慢的滚动,因为在下载和加载图像之前,一切都很顺利,但在加载图像之后,它开始减慢,并且在每次滚动时,将显示的隐藏行会再次重新加载图像。这可能是原因吗?

您必须使用具有滚动功能并随着项目的添加而自动展开的ListView,而不是使用scrollView

第一步,您必须定义一个布局,如下所示

 <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
        <ListView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:id="@android:id/list"
            >

        </ListView>
    </LinearLayout>
}


毕加索是一个你可以下载并直接用来下载图像的图书馆,它有非常好的功能

谢谢Muhannad,我已经在使用毕加索了,它工作起来很有魅力,我会试试这个,我会发帖回来的。在我早期的安卓时代,我遇到了你在回答中提到的同样的问题,但是listView是您在android应用程序中使用的最好的视图,如果您需要关于如何使用listView的任何额外信息,请告诉我我已经编辑了我的问题,请检查一下,看看您是否能找到问题所在?提前感谢您是否可以尝试重新引用以下视图;视图v=转换视图;在方法的末尾返回v;如果“滚动延迟”只是意味着您正在代码中的某个位置锁定主UI线程,而不是返回convertView?它与ScrollView本身无关。锁定主线程意味着对其执行过多CPU密集型工作。这可能是因为图像列表很长,并且没有使用ListView进行虚拟化,因此渲染需要一些时间,或者可能与代码在主线程上执行的操作完全无关。
 <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
        <ListView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:id="@android:id/list"
            >

        </ListView>
    </LinearLayout>
   if(v == null)

      v = View.inflate(context , R.layout.your_item_layout_containing_image);

    ImageView imageView = (ImageView)v.findViewByID(R.id.your_image_view_id);

    Picasso.with(context).load(image_url).into(imageView);
    return v;