本文介紹了可滾動的 TabWidget 或 TabLayout的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
這是我得到的
我得到的類是找不到的.我實際上是在嘗試像 PlayStore
一樣使用 TabWidget
.
我想要那個 gif 那樣的 TabWidget.怎么做?或者,有沒有其他方法可以做到?
我試過了
但是,上面的源代碼沒有給出ScrollableWidget.
我還在 youtube 中找到了一個演示.他給了源碼鏈接http://www.mediafire.com/download/7c1kd878hsvlvzr/tabscroll.rar .但是,我無法訪問該鏈接.
解決方案
創建一個名為 NonSwipeableViewPager 的視圖
這里是 git repo
Here is a library I got.
I had addedimplementation '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 NonSwipeableViewPagerpublic 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的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!