4

ツールバーの下にコンテンツエリアがあります。その動作は、スクロールアップ中にスクロールし、スクロールダウン中にすぐに入力することです。ツールバーは、スクロールせずにその場所に留まる必要があります。AppBarLayoutコンテンツをスクロールするツールバー

私のレイアウトは、そのようなものです:

<?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:id="@+id/coordinator_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".ui.MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     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:popupTheme="@style/AppTheme.PopupOverlay" /> 

     <RelativeLayout 
      android:id="@+id/box_search" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="16dp" 
      android:layout_marginLeft="16dp" 
      android:layout_marginRight="16dp" 
      app:layout_scrollFlags="scroll|enterAlways"> 

      <TextView 
       android:id="@+id/text_search_filter" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Line 1" 
       android:textColor="#FFF" /> 

      <TextView 
       android:id="@+id/text_search_category" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/text_search_filter" 
       android:text="Line 2" 
       android:textColor="#FFF" /> 

      <TextView 
       android:id="@+id/text_search_location" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/text_search_category" 
       android:text="Line 3" 
       android:textColor="#FFF" /> 
     </RelativeLayout> 
    </android.support.design.widget.AppBarLayout> 

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

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:layout_margin="@dimen/fab_margin" 
     android:src="@drawable/ic_add_white_24dp" /> 
</android.support.design.widget.CoordinatorLayout> 

私は、ツールバー上のコンテンツ領域を入れた場合、私は望ましい効果を得ることができていますが、明らかにそれは間違った位置にあります。

私はツールバーの何もスクロール下のコンテンツ領域を置く場合...

答えて

2

:具体的には、これを試してみてください。 http://www.google.com/design/spec/layout/structure.html#structure-app-bar

アンドロイド、でアクションバーの使用目的のツールバーの特別 一種であると以前知られているアプリバー、:それは以来、間違った位置にある。もちろん、

ブランディング、ナビゲーション、検索、および アクション。

したがって、CollapsingToolbarLayoutとその内容を追加する必要があります。

そして:

私は私のツールバーの下のコンテンツ領域を持っているしたいと思います。 スクロールダウン中に がスクロールしている間にスクロールしてすぐに入力すると、その動作は になります。 スクロールせずにツールバーをそのままにしてください。

CollapsingToolbarLayoutことを、あなたはそのToolbarapp:layout_collapseMode="pin"を追加することも追加した後Toolbarをスクロールしないようにするには。

+0

ちょうど試しました。ツールバー(たとえapp:layout_collapseMode = "pin"でも)を含むすべてが崩壊します。:( – Alessandro

+0

私はあなたが 'CollapsingToolbarLayout'に間違ったフラグを使用していると思います。このリンクをチェックしてください:http://guides.codepath .com/android/Handling-Scrolls-with-CoordinatorLayoutしかし、これが最善の方法です。 – Mohsen

+0

私はapp:layout_scrollFlags = "scroll | enterAlways"を使用しています。それが正しい方法だと分かっていますが、私はちょうどできません... – Alessandro

1

アップデート:私のオリジナルの提案は動作しませんでしたので

、望ましい結果を達成するための別の方法は、ツールバーを抜け出すことであろうCoordinatorLayoutから取得します。次のようにあなたのレイアウトXMLを構造化することができます。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    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:orientation="vertical"> 
    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay" /> 
    <android.support.design.widget.CoordinatorLayout 
     android:id="@+id/coordinator_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     tools:context=".ui.MainActivity"> 
     <android.support.design.widget.AppBarLayout 
      android:layout_height="wrap_content" 
      android:layout_width="match_parent" 
      android:theme="@style/AppTheme.AppBarOverlay"> 
      <RelativeLayout 
       android:id="@+id/box_search" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="16dp" 
       android:layout_marginRight="16dp" 
       android:layout_marginBottom="16dp" 
       app:layout_scrollFlags="scroll|enterAlways"> 
       <TextView 
        android:id="@+id/text_search_filter" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="Line 1" 
        android:textColor="#FFF" /> 
       <TextView 
        android:id="@+id/text_search_category" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@id/text_search_filter" 
        android:text="Line 2" 
        android:textColor="#FFF" /> 
       <TextView 
        android:id="@+id/text_search_location" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@id/text_search_category" 
        android:text="Line 3" 
        android:textColor="#FFF" /> 
      </RelativeLayout> 
     </android.support.design.widget.AppBarLayout> 
     <include layout="@layout/content_main" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 
     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/fab" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom|end" 
      android:layout_margin="@dimen/fab_margin" 
      android:src="@drawable/ic_add_white_24dp" /> 
    </android.support.design.widget.CoordinatorLayout> 
</LinearLayout> 

それはまだ動作していない場合は、これが問題の原因であるかもしれないとして、あなたはincludeステートメントを使用しないで検討すべきです。むしろレイアウト定義をこのレイアウトに直接持ち込んで、NestedScrollViewの下に配置します(このNestedScrollViewにapp:layout_behavior = "@ string/appbar_scrolling_view_behavior"を適用します)。追加のヘルプが必要な場合は、content_mainレイアウトXMLの内容をOPに投稿してください。

オリジナルの応答:

アプリを定義していることを確認してください:layout_behaviorメインコンテンツのスクロールがAppBarLayoutに影響を与えるべきであると定義し、あなたのメインのコンテンツ、のために。私は、ツールバー上のコンテンツ領域を入れた場合、私は希望 効果を得ることができていますが、明らかにそれは間違った位置にあります

<include layout="@layout/content_main" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 
+0

私は試しましたが、幸運はありません... – Alessandro

+0

AppBarLayoutからツールバーを抽出すると、ツールバーがコンテンツの下に移動してひどい結果が得られます。 – Alessandro

+0

content_mainレイアウトの内容をポストします。あなたが持っているものを見てみましょう –

関連する問題