java 适用于所有 API 级别的 Android 中的 Tabs+Swipe
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14019981/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Tabs+Swipe in Android for all API levels
提问by Ali
My plan is creating an Activity includes Tabs+Swipe for all Android version. If we set it from a default Android project, it has just support for at least API 11.
我的计划是为所有 Android 版本创建一个包括 Tabs+Swipe 的活动。如果我们从默认的 Android 项目中设置它,它至少只支持 API 11。
In Sherlockwe have two project named : Tab Navigation, Tab Navigation(collapsed) includes Tabs but not Swipe. 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).
在Sherlock 中,我们有两个名为的项目:Tab Navigation,Tab Navigation(collapsed) 包括 Tabs 但不包括 Swipe。它们在其样本中发出#240,其中有一个错误(当标签处于折叠模式(横向)和所选项目不更新时,向左/向右滑动左/右。
Do you know any sample code that solve this problem?
你知道解决这个问题的任何示例代码吗?
采纳答案by Androider
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
回答by sabadow
You made this now with the default Android Support Library (or the ABS), with a ViewPager
and a PagerTabStrip
:
您现在使用默认的 Android 支持库(或 ABS)使用 aViewPager
和 a 进行了此操作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.
然后创建一个Adapter
toViewPager
扩展FragmentStatePagerAdapter
(例如)并覆盖该方法public CharSequence getPageTitle(int position)
以为每个选项卡提供标题。
Hope it helps.
希望能帮助到你。
回答by Lalith B
I found these links which might help you out.
我发现这些链接可能会帮助你。