如何解决可滚动的 TabWidget 或 TabLayout
这是我得到的 library。
我已经添加了
implementation 'ru.noties:scrollable:1.3.0'
到我的build.gradle
。但是,当我实现 TabLayout
ru.noties:scrollable
<ru.noties.scrollable.sample.TabsLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="@dimen/tabs_height"
android:background="@color/md_teal_500"/>
我发现没有找到课程。我实际上是在尝试像 TabWidget
一样使用 PlayStore
。
我想要像那个 gif 那样的 TabWidget。怎么做?或者,有没有其他方法可以做到这一点?
我试过了
<TabHost
android:id="@+id/tab_host"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/rl_">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@android:id/tabs">
<LinearLayout
android:id="@+id/Filters"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
layout="@layout/filters_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="@+id/Adjustments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
layout="@layout/adjustment_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</FrameLayout>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#40cccccc" />
</RelativeLayout>
</TabHost>
但是,上面的源代码没有给出 ScrollableWidget
。
我也在 youtube 中找到了一个演示。他给出了源代码链接 http://www.mediafire.com/download/7c1kd878hsvlvzr/tabscroll.rar 。但是,我无法访问该链接。
解决方法
创建一个名为 NonSwipeableViewPager 的视图
public class NonSwipeableViewPager extends ViewPager {
public NonSwipeableViewPager(Context context) {
super(context);
setMyScroller();
}
public NonSwipeableViewPager(Context context,AttributeSet attrs) {
super(context,attrs);
setMyScroller();
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
// Never allow swiping to switch between pages
return false;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// Never allow swiping to switch between pages
return false;
}
//down one is added for smooth scrolling
private void setMyScroller() {
try {
Class<?> viewpager = ViewPager.class;
Field scroller = viewpager.getDeclaredField("mScroller");
scroller.setAccessible(true);
scroller.set(this,new MyScroller(getContext()));
} catch (Exception e) {
e.printStackTrace();
}
}
public class MyScroller extends Scroller {
public MyScroller(Context context) {
super(context,new DecelerateInterpolator());
}
@Override
public void startScroll(int startX,int startY,int dx,int dy,int duration) {
super.startScroll(startX,startY,dx,dy,350 /*1 secs*/);
}
}
}
这是git repo
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。