Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay and huge lag during switching-scrolling items in ViewPager2 if you try to create big views that fill a big percentage of the screen (neumorphic cardviews,buttons etc. probably in recyclerviews as well) #80

Open
Mon5ta opened this issue May 24, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@Mon5ta
Copy link

Mon5ta commented May 24, 2021

MainActivity ViewPager2 layout

<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".App">

    <androidx.viewpager2.widget.ViewPager2
        android:id="@+id/ViewPager2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">
    </androidx.viewpager2.widget.ViewPager2>

</androidx.constraintlayout.widget.ConstraintLayout>

item_viewpager2

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/itemLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/light_background">

    <soup.neumorphism.NeumorphCardView
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@+id/small"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">
    </soup.neumorphism.NeumorphCardView>

    <soup.neumorphism.NeumorphCardView
        android:id="@+id/small"
        android:layout_width="0dp"
        android:layout_height="50dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent">
    </soup.neumorphism.NeumorphCardView>


</androidx.constraintlayout.widget.ConstraintLayout>

adapter

public class ViewPager2Adapter extends RecyclerView.Adapter<ViewPager2Adapter.ViewHolder> {
    private final List<String> list;

    public ViewPager2Adapter(List<String> list) {
        this.list = list;
    }

    @Override
    public @NotNull ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_viewpager2, viewGroup, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder viewHolder, final int position) {

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public ViewHolder(View view) {
            super(view);

        }
    }
}

MainActivity

public class App extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_main);
        super.onCreate(savedInstanceState);
    
        ViewPager2 viewPager2;
        List<String> list = new ArrayList<>();

        list.add("1");
        list.add("2");
        list.add("3");
        list.add("4");
        list.add("5");
        list.add("6");
        list.add("7");
        list.add("8");

        viewPager2 = findViewById(R.id.anomologitaViewPager2);

        ViewPager2Adapter adapter = new ViewPager2Adapter(list);

        viewPager2.setAdapter(adapter);

    }
}

You will NOT need my code trust me it works fast and fine without the big neumorphic views the smaller the views the better performance

@Mon5ta Mon5ta added the bug Something isn't working label May 24, 2021
@Mon5ta Mon5ta changed the title Delay and huge lag during switching-scrolling items in ViewPager2 if try to create huge views that fill a big percentage of the screen (neumorphic cardviews,buttons etc. probably in recyclerviews as well) Delay and huge lag during switching-scrolling items in ViewPager2 if you try to create big views that fill a big percentage of the screen (neumorphic cardviews,buttons etc. probably in recyclerviews as well) May 24, 2021
@VichitraMac
Copy link

I'm facing the same issue when I'm using it with recycler view

@UvrajSB
Copy link

UvrajSB commented Sep 12, 2021

Me too facing the lag issue with recycler view

@suryamurugesan55
Copy link

Me to facing this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants