1

I did a lot of research before opening this title, but somehow I didn't get the result I wanted. My Listview has accelerated, but it's not enough.

When I make the listview up and down, sometimes it slows down and there are little frosts.

Is this because the Listview only consists of pictures? But when I examine other applications, I see that there is no problem in them.

Would you please review?

This is my adapter code :

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();

    }
}

Sample picture loaded :https://source.unsplash.com/-hI5dX2ObAs/540x720

Phantômaxx
  • 36,442
  • 21
  • 78
  • 108
MuDa Oyunu
  • 11
  • 2

2 Answers2

1

It would be best for you to use a RecyclerView for smooth scrolling and performance. Have a look at this guide to implement it in your app. Also consider using an image loading library like picasso. This is because unsplash has high resolution images, which take time to download. However, an image loader library allows you to cache and compress images so that they can load quickly into your views.

allycat
  • 105
  • 5
0

For smooth scrolling and performance add Recyclerview inside ScrollView and set

 android:nestedScrollingEnabled="false"

This will load all content inside your recyclerview.. otherwise it will only load when you scroll down. This is what i think.

And also set

    @Override
    public int getItemViewType(int position) {
    return position;
   }

inside your recyclerview adapter.
It is to prevent position of the image that will change if you further scroll down and got to top.

SoloWolf93
  • 801
  • 9
  • 22