问题描述
我使用的Android设计支持库的TabLayout。我使用的材料的设计主题。下面是code
I am using the TabLayout from Android Design support library. I am using material design theme. Below is the code
activity_scrollable_Tab.xml
activity_scrollable_Tab.xml
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
scrollableTabActivity.java
scrollableTabActivity.java
public class ScrollableTabsActivity extends AppCompatActivity {
private Toolbar toolbar;
private TabLayout tabLayout;
private ViewPager viewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scrollable_tabs);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
viewPager = (ViewPager) findViewById(R.id.viewpager);
setupViewPager(viewPager);
tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
}
private void setupViewPager(ViewPager viewPager) {
ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
adapter.addFrag(new OneFragment(), "ONE");
adapter.addFrag(new TwoFragment(), "TWO");
.....
adapter.addFrag(new TenFragment(), "TEN");
viewPager.setAdapter(adapter);
}
class ViewPagerAdapter extends FragmentPagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();
public ViewPagerAdapter(FragmentManager manager) {
super(manager);
}
@Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}
@Override
public int getCount() {
return mFragmentList.size();
}
public void addFrag(Fragment fragment, String title) {
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
}
@Override
public CharSequence getPageTitle(int position) {
return mFragmentTitleList.get(position);
}
}
}
标签滚动工作在棒棒糖。但是,同样的code未工作的奇巧和果冻豆设备。在奇巧和果冻豆设备我面临两个问题,
Tab scrolling is working in Lollipop. But the same code is not working on Kitkat and Jelly bean devices. On Kitkat and Jelly bean device I face two problem,
-
当我滚动标签,标签沿着与杰利贝恩和奇巧设备页面导航滚动,但棒棒堂选项卡单独获得滚动,它是工作文件。对于例如:如果1,2,3..10是选项卡,如果我滚动标签,它滚动,每个滚动布局被导航。如果我滚动,标签获取导航到第二个选项卡,然后第三个等。
When I scroll the Tab, Tab is scrolling along with page navigation in Jellybean and kitkat devices, but in Lollipop Tab alone gets scroll and it is working file. For eg: if 1,2,3..10 are the Tab and if I scroll the Tab, it scroll and for each scroll the Layout gets navigated. If I scroll, Tab gets navigate to 2nd Tab and then 3rd and so on.
向上导航不杰利贝恩和奇巧的设备工作。如果我刷工具栏,标签滚动与页面导航发生(上面提到的问题)。
Up navigation is not working in Jellybean and Kitkat devices. If I swipe the Toolbar, Tab scrolling is happening with page navigation (above-mentioned issue).
谁能告诉我可能是什么问题,并在部分我需要检查和排序。我公司可以派APK文件,如果我提供的电子邮件以更好地理解这个问题。
Can anyone tell me what could be the problem and in which portion I need to check and sort it. I can send APK file if provide me the email for a better understanding of the problem.
我是新到Android,需要一些帮助来解决这个问题。
I am new to android, need some help to fix this.
推荐答案
要在奇巧和果冻豆的设备标签滚动的工作,你可以参考本教程
To make Tab scrollable work in kitkat and Jelly bean devices you can refer this tutorial
的
谷歌Docs是还出现此
https://developer.android.com/samples/SlidingTabsBasic/src/com.example.android.common/view/SlidingTabLayout.html
Google docs is also there for thishttps://developer.android.com/samples/SlidingTabsBasic/src/com.example.android.common/view/SlidingTabLayout.html
这是很好的测试,并为我工作在所有设备上
It is well tested and working for me on all devices
这篇关于tabMode =&QUOT;滚动&QUOT;不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!