[英]Tabs+Swipe in Android for all API levels
My plan is creating an Activity includes Tabs+Swipe for all Android version. 我的计划是为所有Android版本创建一个包含Tabs + Swipe的Activity。 If we set it from a default Android project, it has just support for at least API 11. 如果我们从默认的Android项目设置它,它至少支持API 11。
In Sherlock we have two project named : Tab Navigation, Tab Navigation(collapsed) includes Tabs but not Swipe. 在Sherlock,我们有两个项目名称:选项卡导航,选项卡导航(折叠)包括选项卡但不包括滑动。 They have Issue #240 in their samples that has a bug (swipe left/right when the tabs are in collapsed mode (landscape) and the selected item does not update). 他们的样本中有问题#240有错误(当标签处于折叠模式(横向)并且所选项目未更新时向左/向右滑动)。
Do you know any sample code that solve this problem? 你知道任何解决这个问题的示例代码吗?
You made this now with the default Android Support Library (or the ABS), with a ViewPager
and a PagerTabStrip
: 您现在使用默认的Android支持库(或ABS),使用ViewPager
和PagerTabStrip
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.PagerTabStrip
android:id="@+id/tabStrip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"/>
</android.support.v4.view.ViewPager>
</LinearLayout>
Then create an Adapter
to the ViewPager
that extends of FragmentStatePagerAdapter
(for example) and override the method public CharSequence getPageTitle(int position)
to provide a title for each tab. 然后为ViewPager
创建一个Adapter
,该Adapter
扩展FragmentStatePagerAdapter
(例如)并覆盖方法public CharSequence getPageTitle(int position)
以为每个选项卡提供标题。
Hope it helps. 希望能帮助到你。
I also happened to have same situation. 我也碰巧遇到了同样的情况。 Follow below links and you will get all what you need. 按照以下链接,您将获得所需的一切。
See this tutorial http://droidista.blogspot.com/2012/08/making-actionbarsherlock-and.html 请参阅本教程http://droidista.blogspot.com/2012/08/making-actionbarsherlock-and.html
And get demo code from here https://github.com/zmdominguez/vpi-abs-demo 并从这里获取演示代码https://github.com/zmdominguez/vpi-abs-demo
I found these links which might help you out. 我发现这些链接可能会帮助你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.