Android 在具有图像的Listview中性能不佳

Android 在具有图像的Listview中性能不佳,android,listview,android-image,Android,Listview,Android Image,在开始这篇文章之前,我做了很多研究,但不知怎么的,我没有得到我想要的结果。我的Listview加速了,但这还不够 当我上下移动listview时,有时候它会变慢,并且会有一些霜冻 这是因为Listview只包含图片吗?但当我检查其他应用程序时,我发现它们没有问题 请你复习一下好吗 这是我的适配器代码: public class pop_Adapter extends BaseAdapter { private LayoutInflater userInflater; priva

在开始这篇文章之前,我做了很多研究,但不知怎么的,我没有得到我想要的结果。我的Listview加速了,但这还不够

当我上下移动listview时,有时候它会变慢,并且会有一些霜冻

这是因为Listview只包含图片吗?但当我检查其他应用程序时,我发现它们没有问题

请你复习一下好吗

这是我的适配器代码:

public class pop_Adapter extends BaseAdapter  {
    private LayoutInflater userInflater;
    private List<pop_User> userList;
    Activity aa;
    public pop_Adapter(Activity activity, List<pop_User> userList) {
        userInflater = (LayoutInflater) activity.getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);
        aa = activity;
        this.userList = userList;
    }

    @Override
    public int getCount() {
        return userList.size();
    }

    @Override
    public Object getItem(int i) {
        return userList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    class ViewYerTutucu{

        RelativeLayout rela1;
        LinearLayout activity_main,lin1;
        TextView indir;
        ImageView imageViewUserPicture;

        ViewYerTutucu(View v){
            activity_main = (LinearLayout) v.findViewById(R.id.activity_main);
            indir = (TextView) v.findViewById(R.id.indirmeSayisi);
            imageViewUserPicture = (ImageView) v.findViewById(R.id.resim);
            lin1 = (LinearLayout) v.findViewById(R.id.lin1);

            rela1 = (RelativeLayout) v.findViewById(R.id.rela1);
            rela1.getLayoutParams().height = (int) ( (MainActivity.height / MainActivity.width) * MainActivity.width/2 );  //(int)MainActivity.width/2-36;
            indir.setTextSize(MainActivity.pxToDp((int)MainActivity.width/23));

        }

    }


    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {

        View lineView = view;

        ViewYerTutucu tutucu=null;

        if (lineView == null) {
            lineView = userInflater.inflate(R.layout.custom_pop, viewGroup, false);
            tutucu=new ViewYerTutucu(lineView);
            lineView.setTag(tutucu);
        }
        else{
            tutucu= (ViewYerTutucu) lineView.getTag();
        }

        final pop_User user = userList.get(i);

        tutucu.indir.setText(user.getIndirme());

        Glide.with(aa).load(user.getTags()).into(tutucu.imageViewUserPicture);

        final ViewYerTutucu finalTutucu = tutucu;
        tutucu.lin1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MainActivity.hangiBolum = "pop-"+(i*2);
                fragoyunsifir.ResimDegistir(user.getTags());
                fragoyunsifir.paylas.setTag(user.getId());
                fragoyunsifir.indir.setTag(user.getTags());
                fragoyunsifir.button1.setTag(user.getResim());
                Animation fadeOut = AnimationUtils.loadAnimation(aa, R.anim.fade_in_acilis);
                fragoyunsifir.activity_main.startAnimation(fadeOut);
                fadeOut.setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        fragoyunsifir.gorunurYap();
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {

                    }
                });
            }
        });



        tutucu.indir.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(aa, finalTutucu.indir.getText()+" downloads", Toast.LENGTH_SHORT).show();
            }
        });

        if(reachedEndOfList(i)) loadMoreData();

        return lineView;
    }




    private boolean reachedEndOfList(int position) {
        // can check if close or exactly at the end
        return position == getCount() - 1;
    }

    private void loadMoreData() {

        MainActivity.News();

    }
}
公共类pop_适配器扩展BaseAdapter{
私用充气机;
私有列表用户列表;
活动aa;
公共pop_适配器(活动,列表用户列表){
userInflater=(LayoutFlater)activity.getSystemService(
上下文。布局(充气机和服务);
aa=活动;
this.userList=userList;
}
@凌驾
public int getCount(){
返回userList.size();
}
@凌驾
公共对象getItem(int i){
返回userList.get(i);
}
@凌驾
公共长getItemId(int i){
返回i;
}
类ViewYerTutucu{
相对松弛1;
林荫道1的线性布局活动;
TextView indir;
ImageView imageViewUserPicture;
ViewYerTutucu(视图v){
活动\主要=(线性布局)v.findViewById(R.id.activity\主要);
indir=(TextView)v.findViewById(R.id.indirmeSayisi);
imageViewUserPicture=(ImageView)v.findViewById(R.id.resim);
lin1=(线性布局)v.findViewById(R.id.lin1);
rela1=(relatielayout)v.findViewById(R.id.rela1);
rela1.getLayoutParams().height=(int)((MainActivity.height/MainActivity.width)*MainActivity.width/2);/(int)MainActivity.width/2-36;
indir.setTextSize(MainActivity.pxToDp((int)MainActivity.width/23));
}
}
@凌驾
公共视图getView(最终int i、视图视图、视图组视图组){
视图lineView=视图;
ViewYerTutucu-tutucu=null;
if(lineView==null){
lineView=userInflater.inflate(R.layout.custom_pop,viewGroup,false);
tutucu=新视口tutucu(线视图);
lineView.setTag(tutucu);
}
否则{
tutucu=(viewyerttucu)lineView.getTag();
}
最终pop_User=userList.get(i);
tutucu.indir.setText(user.getIndirme());
将(user.getTags())加载到(tutucu.imageViewUserPicture)中;
最终视图tutucu finalTutucu=tutucu;
tutucu.lin1.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
MainActivity.hangiBolum=“pop-”+(i*2);
ResimDegistir(user.getTags());
fragoyunsifir.paylas.setTag(user.getId());
fragoyunsifir.indir.setTag(user.getTags());
fragoyunsifir.button1.setTag(user.getResim());
动画淡出=AnimationUtils.loadAnimation(aa,R.anim.fade\u in\u acilis);
fragoyunsifir。主要活动。启动(衰减);
fadeOut.setAnimationListener(新的Animation.AnimationListener(){
@凌驾
onAnimationStart上的公共无效(动画){
}
@凌驾
onAnimationEnd上的公共无效(动画){
fragoyunsifir.gorunurYap();
}
@凌驾
onAnimationRepeat上的公共无效(动画){
}
});
}
});
tutucu.indir.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
Toast.makeText(aa,finalTutucu.indir.getText()+“下载”,Toast.LENGTH\u SHORT.show();
}
});
如果(到达EndofList(i))加载更多数据();
返回线视图;
}
私有布尔reachedEndOfList(int位置){
//可以检查是否接近或恰好在末尾
返回位置==getCount()-1;
}
私有void loadMoreData(){
MainActivity.News();
}
}

加载的示例图片:

最好使用RecyclerView以实现平滑滚动和性能。看看这个,在你的应用程序中实现它。也可以考虑使用像这样的图像加载库。这是因为unsplash具有高分辨率图像,下载需要时间。但是,图像加载器库允许您缓存和压缩图像,以便它们可以快速加载到视图中。

为了平滑滚动和提高性能,请在ScrollView中添加Recyclerview并设置

 android:nestedScrollingEnabled="false"
这将加载recyclerview中的所有内容。。否则,它将仅在向下滚动时加载。这就是我的想法。

而且还设置了

    @Override
    public int getItemViewType(int position) {
    return position;
   }
在您的recyclerview适配器内。

这是为了防止图像的位置在进一步向下滚动并到达顶部时发生变化。

您应该使用RecyclerWebUse RecycleWebUse使用毕加索或Glide图像加载库,然后如果图像较小(如缩略图),则加载缩略图,而不是在大预览中加载完整图像。@volkanshin45,我试过,但结果相同:(Unsplash具有非常高的清晰度图像。这可能会导致您的滚动出现问题。我已经使用glide。我也尝试了recylerview,但结果没有改变。您是否正在使用来自对Unsplash api的网络请求的数据填充您的列表?哦,好的,您如何发出这些请求以及如何解析它们?我将链接发送到适配器从activity开始,用glide加载。好吧,那么你不是在使用网络库发出请求和JSON解析库吗?