0

コーディングツールバーをコーディネーターのレイアウトで使用しましたが、折りたたみバーはまだ折りたたまれずにスクロールしたままです。コーディネーターのレイアウトでスクロールするときにツールバーを折りたたんでいない

これはactivity_demo.xmlである - これはDemoActivity.javaある

<?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.support.design.widget.AppBarLayout 
      android:id="@+id/appbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
      android:fitsSystemWindows="true"> 

<!-- Fit the system windows for your CollapsingToolbarLayout 
      also set your height to wrap_content and give image a height--> 

<android.support.design.widget.CollapsingToolbarLayout 
       android:id="@+id/collapsing_toolbar" 
       android:fitsSystemWindows="true" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       app:contentScrim="?attr/colorPrimary" 
       app:expandedTitleMarginStart="4dp" 
       app:expandedTitleMarginEnd="64dp"> 

       <ImageView 
        android:id="@+id/backdrop" 
        android:layout_width="match_parent" 
        android:layout_height="244dp" 
        android:scaleType="centerCrop" 
        android:fitsSystemWindows="true" 
        android:src="@drawable/cheese" 
        app:layout_collapseMode="parallax"/> 
       <!-- Tell your toolbar to scroll|enterAlways --> 
       <android.support.v7.widget.Toolbar 
        android:id="@+id/toolbar" 
        android:layout_width="match_parent" 
        android:layout_height="?attr/actionBarSize" 
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
        app:layout_scrollFlags="scroll|enterAlways"/> 
       <!-- add layout_gravity="bottom" --> 
       <android.support.design.widget.TabLayout 
        android:id="@+id/tabs" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        app:tabSelectedTextColor="?android:attr/textColorPrimaryInverse" 
        app:tabIndicatorColor="?android:attr/textColorPrimaryInverse" 
        app:tabIndicatorHeight="4dp" 
        android:layout_gravity="bottom"/> 
      </android.support.design.widget.CollapsingToolbarLayout> 
     </android.support.design.widget.AppBarLayout> 

     <android.support.v4.widget.NestedScrollView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical" 
       android:paddingTop="24dp"> 

       <android.support.v7.widget.CardView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_margin="16dp"> 

        <LinearLayout 
         style="@style/Widget.CardContent" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content"> 

         <TextView 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content" 
          android:text="Info" 
          android:textAppearance="@style/TextAppearance.AppCompat.Title" /> 

         <TextView 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content" 
          android:text="@string/cheese_ipsum" /> 

        </LinearLayout> 

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

       <android.support.v7.widget.CardView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginBottom="@dimen/card_margin" 
        android:layout_marginLeft="@dimen/card_margin" 
        android:layout_marginRight="@dimen/card_margin"> 

        <LinearLayout 
         style="@style/Widget.CardContent" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content"> 

         <TextView 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content" 
          android:text="Friends" 
          android:textAppearance="@style/TextAppearance.AppCompat.Title" /> 

         <TextView 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content" 
          android:text="@string/cheese_ipsum" /> 

        </LinearLayout> 

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

       <android.support.v7.widget.CardView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginBottom="@dimen/card_margin" 
        android:layout_marginLeft="@dimen/card_margin" 
        android:layout_marginRight="@dimen/card_margin"> 

        <LinearLayout 
         style="@style/Widget.CardContent" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content"> 

         <TextView 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content" 
          android:text="Related" 
          android:textAppearance="@style/TextAppearance.AppCompat.Title" /> 

         <TextView 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content" 
          android:text="@string/cheese_ipsum" /> 

        </LinearLayout> 

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

      </LinearLayout> 

     </android.support.v4.widget.NestedScrollView> 
    </android.support.design.widget.CoordinatorLayout> 

-

package com.example.priyanshu.iitmandi; 

    import android.os.Bundle; 
    import android.support.design.widget.CollapsingToolbarLayout; 
    import android.support.v7.app.AppCompatActivity; 
    import android.support.v7.widget.Toolbar; 
    import android.widget.ImageView; 

public class DemoActivity extends AppCompatActivity { 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_demo); 

     final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 
     getSupportActionBar().setDisplayHomeAsUpEnabled(true); 

     CollapsingToolbarLayout collapsingToolbar = 
       (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); 
     collapsingToolbar.setTitle("Faculty"); 

     loadBackdrop(); 
    } 

    private void loadBackdrop() { 
     final ImageView imageView = (ImageView) findViewById(R.id.backdrop); 

     imageView.setImageResource(R.drawable.cheese); 
    } 

} 

活動のスクリーンショットが必要な場合、私はこの提案を試してみてください

+0

ここをクリックしてください:http://guides.codepath.com/android/handling-scrolls-with-coordinatorlayout#creating-collapsing-effects –

答えて

1

を知ってみましょう:

1にapp:layout_scrollFlagsを追加していません

app:layout_scrollFlags="scroll|enterAlways|snap" //add this 
app:contentScrim="?attr/colorPrimary" 
app:expandedTitleMarginStart="48dp" 
app:expandedTitleMarginEnd="64dp" 

2.Next事がCollapsingToolbarLayoutの外に<android.support.design.widget.TabLayoutを入れて、時にはそれが所望の出力を与えるandroid:fillViewport="true"を追加AppBarLayout

3.InあなたNestedScrollviewの下に追加します。あなたもCollapsingToolbarLayout

app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed" 

、それがスクロール中のツールバーを固定しますToolbar

app:layout_collapseMode="pin" 
app:layout_scrollFlags="scroll|exitUntilCollapsed" 

ため..

のために試すことができます

<android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:fillViewport="true" 

EDIT

+0

ありがとうございます!!それはうまくいったが、折りたたみツールバーをスクロールすると、画像とタイトルの両方が消えてしまうという小さな問題がありました。小さなサイズに収縮してそこにとどまりたいのです(タイトルのみが表示されるはずです) – Somebody

+0

: 'app:layout_scrollFlags =" scroll | enterAlways | enterAlwaysCollapsed "'フラグの詳細を知る:http://guides.codepath.com/android/handling-scrolls-with-coordinatorlayout#creating-collapsing-effects – rafsanahmad007

+0

エラー:(22、37)文字列の型は許可されません( 'layout_scrollFlags'の値が 'scroll | enterAlways | enterAlwaysCollap sed'のところで)。このエラーは、ちょうど – Somebody

関連する問題