0

私は主なアクティビティでCollapsingToolBarLayoutを使用していますが、一部のフラグメントで拡張可能にしたいだけです。これを行うために、私はこれらのメソッドを使用しています(フラグメントトランザクションの直後/デタッチ)。これらのメソッドは、ツールバーのアニメーション化に成功しましたが、lockAppBarClosedを呼び出したフラグメントではまだ拡張可能です。CollapsingToolBarLayoutがプログラムで拡張されないようにします。

public void unlockAppBarOpen(boolean animate){ 
    appBarLayout.setExpanded(true, animate); 
    appBarLayout.setEnabled(true); 
    appBarLayout.setActivated(true); 
} 
public void lockAppBarClosed(boolean animate){ 
    appBarLayout.setExpanded(false, animate); 
    appBarLayout.setEnabled(false); 
    appBarLayout.setActivated(false); 
} 

setEnabledsetActivatedは何もしないように見えます。参考のため

は、ここに私のapp_bar_main.xmlファイルです:私はLayoutParams()を経由してAppBarLayoutの高さを設定しようとしました

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appbar" 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/app_bar_extended" 
    android:fitsSystemWindows="true" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 
    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/collapsing_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true" 
     app:contentScrim="?attr/colorPrimary" 
     app:expandedTitleTextAppearance="@android:color/transparent" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed"> 
     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      app:layout_collapseMode="pin" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 
    </android.support.design.widget.CollapsingToolbarLayout> 
</android.support.design.widget.AppBarLayout> 

<FrameLayout 
    android:id="@+id/fragment_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:focusable="true" 
    android:clickable="true" 
    android:background="?android:attr/selectableItemBackground" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 
</FrameLayout> 

が、これ、のためのいくつかの理由は、animateがtrueに設定されている場合でも、アニメーションが再生されないようにします。スクロールフラグをnoneまたはalways collapsedに設定すると何も起こりません。スクロールsnapのいずれかのエフェクトも探していません。

理想的には、(通常と同じように)1つのフラグメント内にアプレットのアニメーションが存在しないようにし、フラグメント間や希望する間にアニメーションを折りたたむ/展開するのが理想です。

ご意見がありましたら、高く評価されます。 ありがとうございます。

答えて

0

activity_main.xmlでCollapsingToolBarLayoutを使用する代わりに、主なアクティビティにアクションバーまたは通常のツールバーを使用することをお勧めします。ここでは、CollapsingToolBarLayoutにアクセスしたいxml以下のようなフラグメントのファイル:

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

      <android.support.design.widget.AppBarLayout 
       android:id="@+id/app_bar_layout" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 

       android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
       android:fitsSystemWindows="true"> 

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

        app:expandedTitleMarginStart="48dp" 
        app:expandedTitleMarginEnd="64dp" 
        android:fitsSystemWindows="true"> 

        <ImageView 
       android:id="@+id/pager" 
       android:layout_width="match_parent" 
       android:layout_height="250dp"> 
      </ImageView> 

        <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:expandedTitleTextAppearance="@style/CollapsingToolbarLayoutExpandedTextStyle" 
         app:layout_collapseMode="pin" > 

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

       </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" 
       android:layout_gravity="fill_vertical" 
       android:layout_marginBottom="?attr/actionBarSize" 
       app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

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

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





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

    where the specific_content.xml is an xml file that carries the fragment contents. 

    In the fragment code where you want the CollapsingToolBarLayout, disable the MainActivity actionbar/toolbar and you can see the CollapsingToolBarLayout there. Hope that will help. Happy coding. 
0

使用mAppBarLayout.setExpanded(true)ツールバーを拡張し、プログラムツールバーを折りたたむにmAppBarLayout.setExpanded(false)を使用します。

は、あなたがプログラムで CollapsingToolbarLayout高さを変更するmAppBarLayout.setLayoutParams(params)を使用する必要があり、その後拡大してからCollapsingToolbarLayoutないようにしたい場合。

崩壊:

CoordinatorLayout.LayoutParams params =(CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams(); 
params.height = 3*80; // COLLAPSED_HEIGHT 

mAppBarLayout.setLayoutParams(params); 
mAppBarLayout.setExpanded(false); 

展開:

CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams(); 
params.height = 3*200; // EXPANDED_HEIGHT 

mAppBarLayout.setLayoutParams(params); 
mAppBarLayout.setExpanded(true); 

希望これはあなたに役立ちます〜

関連する問題