2015-07-18 39 views
-1

我已經嘗試了幾篇不同的文章,這裏有很多線索和教程,但我無法得到這個做任何事情。AppBarLayout拒絕做任何事

在我的代碼中,使用此佈局的活動是AppCompatActivity。 我有AppCompatTheme.Light.NoActionBar

在我的活動內我設置setSupportActionBar()到視圖R.id.toolbar

這是我的目標:http://imgur.com/Hl2Asb1.gif

// Dependencies 
compile 'com.android.support:appcompat-v7:21.0.3' 
compile 'com.android.support:cardview-v7:21.0.2' 
compile 'com.android.support:recyclerview-v7:21.0.2' 
compile 'com.android.support:appcompat-v7:21.0.3' 
compile 'com.android.support:support-v13:21.0.3' 
compile 'com.android.support:multidex:1.0.0' 
compile 'com.android.support:design:22.2.0' 
compile 'com.squareup.picasso:picasso:2.5.2' 
compile 'com.jakewharton:butterknife:6.1.0' 

這裏是我的xml:

<?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" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

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

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


    <android.support.v7.widget.RecyclerView 
     android:id="@+id/listview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 
</android.support.design.widget.CoordinatorLayout> 
+0

你有兩個'工具欄'的特殊原因嗎?你可以包含你的'build.gradle'文件的依賴關係嗎? – ianhanniballake

+0

添加了我的依賴關係。我有兩個'工具欄',因爲我只是想要得到一些結果。 – Sherlock

+0

我從xml中移除了第二個工具欄,以避免任何進一步的混淆。 – Sherlock

回答

3

您必須使用RecyclerView至少版本22.2.0(目前22.2.1)採取的設計庫功能優勢,如AppBarLayout

compile 'com.android.support:recyclerview-v7:22.2.1' 

正是在22.2.0是他們添加了對嵌套滾動的支持,這是AppBarLayout依賴的基礎功能。

-1

放置RecyclerviewAppBarLayout的頂部像這樣 `

<?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" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/listview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

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

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


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


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



</android.support.design.widget.CoordinatorLayout>` 

爲什麼使用兩個Toolbars?只是想知道...

+0

更改RecyclerView的位置沒有區別。 – Sherlock