引入依赖
implementation ('com.github.Chrisvin:LiquidSwipe:1.3')
SwipeActivity.java
LiquidSwipeViewPager pager = (LiquidSwipeViewPager) findViewById(R.id.pager);
final List<Fragment> fragments = new ArrayList<>();
fragments.add(new Fragment(R.layout.f1));
fragments.add(new Fragment(R.layout.f2));
fragments.add(new Fragment(R.layout.f3));
pager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager(),BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
@NonNull
@Override
public Fragment getItem(int position) {
return fragments.get(position);
}
@Override
public int getCount() {
return fragments.size();
}
});
activity_swipe.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.jem.liquidswipe.LiquidSwipeViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
f1.xml
<?xml version="1.0" encoding="utf-8"?>
<com.jem.liquidswipe.layout.LiquidSwipeConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:background="#2196F3"
android:layout_height="match_parent">
</com.jem.liquidswipe.layout.LiquidSwipeConstraintLayout>
f2.xml
<?xml version="1.0" encoding="utf-8"?>
<com.jem.liquidswipe.layout.LiquidSwipeConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:background="#FB0303"
android:layout_height="match_parent">
</com.jem.liquidswipe.layout.LiquidSwipeConstraintLayout>
f3.xml
<?xml version="1.0" encoding="utf-8"?>
<com.jem.liquidswipe.layout.LiquidSwipeConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:background="#00BCD4"
android:layout_height="match_parent">
</com.jem.liquidswipe.layout.LiquidSwipeConstraintLayout>
GitHub依赖库地址:https://github.com/568/LiquidSwipe