可滚动的TabWidget或TabLayout [英] Scrollable TabWidget or TabLayout
问题描述
这是我得到的
我正在找到课程.我实际上是在尝试像 PlayStore
这样使用 TabWidget
.
我希望TabWidget像这样的gif.怎么做?或者,还有其他替代方法吗?
我尝试过
< TabHostandroid:id =" @ + id/tab_host"android:layout_width =" match_parent"android:layout_height =" match_parent"android:layout_above =" @ id/rl_">< RelativeLayoutandroid:layout_width =" match_parent"android:layout_height =" match_parent"android:orientation =" vertical">< FrameLayoutandroid:id =" @android:id/tabcontent"android:layout_width =" match_parent"android:layout_height =" wrap_content"android:layout_above =" @android:id/tabs">< LinearLayoutandroid:id ="@@ id/Filters"android:layout_width =" match_parent"android:layout_height =" wrap_content"android:orientation =" vertical"><包括布局="@ layout/filters_layout";android:layout_width =" match_parent"android:layout_height =" wrap_content"/></LinearLayout>< LinearLayoutandroid:id ="@@ id/Adjustments"android:layout_width =" match_parent"android:layout_height =" match_parent"android:orientation =" vertical"><包括布局="@ layout/adjustment_layout";android:layout_width =" match_parent"android:layout_height =" match_parent"/></LinearLayout></FrameLayout>< TabWidgetandroid: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的视图
公共类NonSwipeableViewPager扩展了ViewPager {公共NonSwipeableViewPager(上下文上下文){超级(上下文);setMyScroller();}public NonSwipeableViewPager(Context context,AttributeSet attrs){超级(上下文,attrs);setMyScroller();}@Overridepublic boolean onInterceptTouchEvent(MotionEvent event){//禁止在页面之间切换返回false;}@Overridepublic boolean onTouchEvent(MotionEvent event){//禁止在页面之间切换返回false;}//添加下一个以平滑滚动私人无效setMyScroller(){尝试 {类<?>viewpager = ViewPager.class;字段滚动器= viewpager.getDeclaredField("mScroller");scroller.setAccessible(true);scroller.set(this,new MyScroller(getContext()));} catch(Exception e){e.printStackTrace();}}公共类MyScroller扩展了Scroller {公共MyScroller(上下文上下文){超级(上下文,新的DecelerateInterpolator());}@Overridepublic void startScroll(int startX,int startY,int dx,int dy,int duration){super.startScroll(startX,startY,dx,dy,350/* 1秒*/);}}}
这是 git回购
Here is a library I got.
I had added
implementation 'ru.noties:scrollable:1.3.0'
to my build.gradle
. But, when I implement TabLayout
of 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"/>
I am getting the class isn't found. I am actually trying to use TabWidget
like PlayStore
.
I want TabWidget like that gif. How to do that? Or, is there any alternative way to do it?
I tried
<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>
But, above source code don't gives ScrollableWidget
.
I found an demo in youtube also. He gave source code link http://www.mediafire.com/download/7c1kd878hsvlvzr/tabscroll.rar . But, I am unable to visit that link.
Create a view called 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*/);
}
}
}
Here's the git repo
这篇关于可滚动的TabWidget或TabLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!