gpt4 book ai didi

java - Android 中的 Tabs+Swipe 适用于所有 API 级别

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:16:14 25 4
gpt4 key购买 nike

我的计划是为所有 Android 版本创建一个包含 Tabs+Swipe 的 Activity 。如果我们从默认的 Android 项目设置它,它至少只支持 API 11。

Sherlock我们有两个项目名为:Tab Navigation,Tab Navigation(collapsed) 包括 Tabs 但不包括 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).

你知道解决这个问题的示例代码吗?

最佳答案

您现在使用默认的 Android 支持库(或 ABS)、ViewPagerPagerTabStrip 完成此操作:

<?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>

然后为 ViewPager 创建一个 Adapter,它扩展了 FragmentStatePagerAdapter(例如)并覆盖方法 public CharSequence getPageTitle( int position) 为每个选项卡提供标题。

希望对您有所帮助。

关于java - Android 中的 Tabs+Swipe 适用于所有 API 级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14019981/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com