【发布时间】:2016-07-29 12:08:49
【问题描述】:
我按照这些教程Android TabLayout Example using ViewPager and Fragments Android TabLayout Example
但如果我滑动片段,视图寻呼机将不会移动。 我得到了这个结果output I got 我按照上面的教程只是没有变化,但是当我们滑动片段时,选项卡不会移动。请帮我。提前致谢。
这是activity_main.xml
<LinearLayout
android:id="@+id/main_layout"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!-- our toolbar -->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<!-- our tablayout to display tabs -->
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<!-- View pager to swipe views -->
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
【问题讨论】:
-
显示一些代码。 Android Studio 中还有一个默认模板,在创建 Activity 时,选择 Activity with tabs + ViewPager,你会得到一个可以检查和学习的工作代码。
-
我按照上面的教程完美运行,除了这个问题。当我滑动标签时不会切换为什么?
-
不知道没有你的代码。没有人会。请分享相关代码(尤其是您声明 TabLayout 的 xml)。
-
确保在 Activity 中使用 tablayout 设置查看器:
tabLayout.setupWithViewPager(yourViewPager); -
您发现问题了吗?
标签: android android-layout android-viewpager swipe