我正在使用库来滑动标签SmartTabLayout - ogaclejapan。我想在父滑动选项卡的一个选项卡中添加一个滑动选项卡。但是当我这样做时,我看不到第二个滑动标签。
以下是包含父级滑动标签的MainActivity。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:id="@+id/root"
tools:context="com.virtualsquadz.letsgo.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:id="@+id/topBar"
android:layout_marginTop="@dimen/_16sdp"
android:paddingBottom="@dimen/_5sdp">
<ImageButton
android:layout_width="wrap_content"
android:id="@+id/backButton"
android:layout_height="wrap_content"
android:src="@drawable/back_0"
android:background="@null"
android:layout_alignParentLeft="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/title_transport"
android:text="Getting Around"
style="@style/title_transport"
android:paddingTop="@dimen/_2sdp"
android:layout_centerInParent="false"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
<com.ogaclejapan.smarttablayout.SmartTabLayout
android:id="@+id/viewpagertab"
android:layout_below="@id/topBar"
android:layout_width="match_parent"
android:layout_height="48dp"
app:stl_indicatorAlwaysInCenter="false"
app:stl_indicatorWithoutPadding="false"
app:stl_indicatorInFront="false"
app:stl_indicatorInterpolation="smart"
app:stl_indicatorGravity="bottom"
app:stl_indicatorColor="#40C4FF"
app:stl_indicatorThickness="4dp"
app:stl_indicatorWidth="auto"
app:stl_indicatorCornerRadius="2dp"
app:stl_overlineColor="#4D000000"
app:stl_overlineThickness="0dp"
app:stl_underlineColor="#4D000000"
app:stl_underlineThickness="1dp"
app:stl_dividerColor="#4D000000"
app:stl_dividerThickness="1dp"
app:stl_defaultTabBackground="?attr/selectableItemBackground"
app:stl_defaultTabTextAllCaps="true"
app:stl_defaultTabTextColor="@color/flight_white"
app:stl_defaultTabTextSize="@dimen/_12sdp"
app:stl_defaultTabTextHorizontalPadding="@dimen/_16sdp"
app:stl_defaultTabTextMinWidth="0dp"
app:stl_distributeEvenly="true"
app:stl_clickable="true"
app:stl_titleOffset="24dp"
app:stl_drawDecorationAfterTab="false"
/>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/viewpagertab"
android:layout_marginTop="@dimen/_5sdp"
/>
</RelativeLayout>
MainActivity.java
SmartTabLayout viewPagerTab = (SmartTabLayout) findViewById(R.id.viewpagertab);
ViewPager viewPager=(ViewPager)findViewById(R.id.viewpager) ;
ViewPagerItemAdapter adapter = new ViewPagerItemAdapter(ViewPagerItems.with(this)
.add(R.string.transportOption1, R.layout.activity_flights)
.add(R.string.transportOption2, R.layout.activity_train)
.add(R.string.transportOption3, R.layout.activity_buses)
.add(R.string.transportOption4, R.layout.activity_cars)
.create());
viewPager.setAdapter(adapter);
viewPagerTab.setViewPager(viewPager);
类似我为train.java里面的'火车'设计了
SmartTabLayout viewPagerTab = (SmartTabLayout) findViewById(R.id.viewpagertab2);
ViewPager viewPager=(ViewPager)findViewById(R.id.viewpager2) ;
ViewPagerItemAdapter adapter = new ViewPagerItemAdapter(ViewPagerItems.with(this)
.add(R.string.trainSearchOption1, R.layout.trainsearchoption1)
.add(R.string.trainSearchOption2, R.layout.trainsearchoption2)
.create());
viewPager.setAdapter(adapter);
viewPagerTab.setViewPager(viewPager);
我试图从here找到解决方案。但不幸的是我找不到答案。如果你想知道在嵌套时应该调用哪个ViewPager然后以一个情况为例 - 当向左/向右翻转时以及当我们分别在子视图分页器的左/右末端然后父视图时调用第一个子视图分页器寻呼机被调用。或者我们也可以点击父母的标签来改变它。