2016-11-29 30 views
0

內部如何能夠做到以下佈局的設計,其中上滾動了,我剛剛得到的觀點與搜索查看:搜索查看協調佈局

1 ----

enter image description here

2 ----- -On滾動起來:

enter image description here

我試圖把意見在某些地方的佈局,但搜索查看最後總是在最上方的區域,而不是低於家庭徽標或甚至不可見。

我沒有任何搜索查看當前的佈局是:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 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" 
android:background="#CFD8DC" 
android:fitsSystemWindows="true" 
tools:context="com.example.svatts.my22.ScrollingActivity"> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/app_bar" 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/app_bar_height" 
    android:fitsSystemWindows="true" 
    android:theme="@style/AppTheme.AppBarOverlay"> 


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

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="56dp" 
       app:layout_collapseMode="pin" 

       app:popupTheme="@style/AppTheme.PopupOverlay"> 

      </android.support.v7.widget.Toolbar> 


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

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

    <include layout="@layout/content_scrolling" /> 

</android.support.design.widget.CoordinatorLayout> 
+0

嘗試[NestedScrollView](http://stackoverflow.com/a/30574304/6005977) –

+0

可以詳細說明一下,我已經在content_scrolling中使用nestedscrollview,它的目的是讓'app:layout_behavior = @ string/appbar_scrolling_view_behaviour' – user3820753

回答

0

改變你的整個工具欄,下面和思想這條線:

app:layout_scrollFlags="scroll|enterAlways|snap" 



<android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:layout_scrollFlags="scroll|enterAlways|snap"> 

然後在工具欄下有tabMode滾動像這樣添加您的看法:

<your.search.layout 
     android:id="@+id/your_search_layout_id" 
     android:layout_width="match_parent" 
     android:layout_height="your_height" 
     app:tabMode="scrollable"/> 

並添加以下佈局到您的content_scrolling你wa NT與標籤欄

app:layout_behavior="@string/appbar_scrolling_view_behavior" 

工作實例

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:layout_scrollFlags="scroll|enterAlways|snap"> 

    </android.support.v7.widget.Toolbar> 

    <android.support.design.widget.TabLayout 
     android:id="@+id/tab_layout_main" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:tabMode="scrollable"/> 
</android.support.design.widget.AppBarLayout> 


<android.support.v4.view.ViewPager 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 
+0

我剛剛嘗試過這種方式,我用作搜索視圖的editText即將到達頂部(正好在狀態欄下方),並且在滾動時消失。 – user3820753

+0

增加了一個工作示例。隨着以下gradle內部版本: compileSdkVersion 23 buildToolsVersion「23.0.3」 – jobbert

+0

它現在工作嗎? – jobbert

0

滾動您可以使用NestedScrollView爲此與AppBarLayout一起。爲了更好的兼容性使用EditText而不是SearchView

更多信息here