0

我想在工具欄和摺疊工具欄中的標籤佈局之間放置一個滑塊,就像tv showtime app中的那個一樣。我試圖用ViewPager + 2碎片替換ImageView,但它不起作用。 collapsing toolbar還有其他解決方案嗎?如何將滑塊放在Android上的摺疊佈局中?

電視欣欣應用

enter image description here

摺疊式工具

enter image description here

MainActivity.java

<android.support.design.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/rootlayout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true"> 

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:fitsSystemWindows="true" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/collapse_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="250dp" 
     android:fitsSystemWindows="true" 
     app:contentScrim="?attr/colorPrimary" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

     <android.support.v4.view.ViewPager 
      android:id="@+id/slider" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 
     </android.support.v4.view.ViewPager> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="100dp" 
      android:gravity="top" 
      android:minHeight="?attr/actionBarSize" 
      app:layout_collapseMode="pin" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
      app:titleMarginTop="15dp" /> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:layout_gravity="bottom" 
      app:tabIndicatorColor="@color/colorAccent" > 

     </android.support.design.widget.TabLayout> 

    </android.support.design.widget.CollapsingToolbarLayout> 

</android.support.design.widget.AppBarLayout> 

<android.support.v4.view.ViewPager 
    android:id="@+id/viewpager" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 
</android.support.design.widget.CoordinatorLayout> 

slides.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:srcCompat="@drawable/slide1" 
    android:id="@+id/imageView" /> 
</LinearLayout> 
+0

嘗試添加標籤佈局正下方的塌陷行動起來吧? –

+0

這不是我想要做的,我想在摺疊工具欄中左/右插入滑塊 –

+0

看看這種方法 - http://stackoverflow.com/q/32666276 –

回答