1

私はツールバーを折りたたむときに、TextViewを含むAndroidサポートの折りたたみツールバーにレイアウトがあります。一部のTextViewがツールバーのタイトルで表示されます。 ツールバーとタイトルではなく、他のすべてのものを隠したい。 私のレイアウトです。 Android折りたたみツールバーが折りたたまれている間に他の要素を隠していませんでした

<android.support.design.widget.AppBarLayout 
    android:id="@+id/MyAppbar" 
    android:layout_width="match_parent" 
    android:layout_height="256sp" 
    android:fitsSystemWindows="true"> 
    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/collapse_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed" 
     android:background="#ff009688" 
     app:contentScrim="@color/colorPrimary" 
     app:expandedTitleMarginTop="100sp" 
     app:expandedTitleGravity="center|bottom" 
     android:fitsSystemWindows="true"> 
     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:scaleType="fitXY" 
      app:srcCompat="@drawable/bgimg" 
      app:layout_collapseMode="parallax"/> 
     <android.support.v7.widget.Toolbar 
      android:id="@+id/MyToolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      app:layout_collapseMode="pin" /> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      app:layout_anchor="@+id/MyAppbar" 
      android:layout_height="match_parent"> 
      <de.hdodenhof.circleimageview.CircleImageView 
       android:id="@+id/profile_image" 
       android:layout_width="96dp" 
       android:layout_height="96dp" 
       android:src="@drawable/studentprofile" 
       app:civ_border_width="2dp" 
       app:civ_border_color="#0adcf4" 
       android:layout_marginTop="58dp" 
       android:layout_alignParentTop="true" 
       android:layout_centerHorizontal="true" /> 

      <TextView 
       android:id="@+id/branch" 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content" 
       android:text="Branch: " 
       android:textColor="@color/textColorPrimary" 
       android:textSize="14sp" 
       android:layout_marginBottom="20sp" 
       android:layout_alignParentBottom="true" 
       android:layout_centerInParent="true" /> 
     </RelativeLayout> 
    </android.support.design.widget.CollapsingToolbarLayout> 

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

そして、私のJavaコードがある...

collapsingToolbar = 
      (CollapsingToolbarLayout) findViewById(R.id.collapse_toolbar); 
    collapsingToolbar.setTitle(name); 
    collapsingToolbar.setExpandedTitleTextAppearance(R.style.expandedappbar); 
    collapsingToolbar.setCollapsedTitleTextAppearance(R.style.collapsedappbar); 
    final ImageView profile=(ImageView)findViewById(R.id.profile_image); 
    Picasso.with(this) 
      .load(photo_url) 
      .placeholder(R.drawable.studentprofile) 
      .networkPolicy(NetworkPolicy.NO_CACHE) 
      .into(new Target() { 
       @Override 
       public void onBitmapLoaded (final Bitmap bitmap, Picasso.LoadedFrom from){ 
       /* Save the bitmap or do something with it here */ 
        Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() { 

         @Override 
         public void onGenerated(Palette palette) { 
          collapsingToolbar.setContentScrimColor(palette.getMutedColor(ContextCompat.getColor(context,R.color.colorPrimary))); 
          collapsingToolbar.setStatusBarScrimColor(palette.getMutedColor(ContextCompat.getColor(context,R.color.colorPrimaryDark))); 
         } 
        }); 
        //Set it in the ImageView 
        profile.setImageBitmap(bitmap); 
       } 

       @Override 
       public void onBitmapFailed(Drawable errorDrawable) { 
       } 

       @Override 
       public void onPrepareLoad(Drawable placeHolderDrawable) { 
       } 
      }); 

答えて

2

私はそれが他の人のために参考になっますので、私自身は、私はこの答えを投稿しています私の問題を解決しているので。 CollapsingToolBarFrameLayoutに拡張されているので、別のタグの後に書かれたxmlタグは、親の一番上に重ねられます。私のRelativeLayoutは、Toolbarの後に書かれています。なぜRelative Layoutの要素がToolbarに表示されているのですか?CollapsingToolbarが崩壊しました。 Toolbarの前にRelativeLayoutを置くだけで、ツールバーが折りたたまれた後に要素が非表示になります。このツールバーをやった後

<android.support.design.widget.CollapsingToolbarLayout 
    android:id="@+id/collapse_toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_scrollFlags="scroll|exitUntilCollapsed" 
    android:background="#ff009688" 
    app:contentScrim="@color/colorPrimary" 
    app:expandedTitleMarginTop="100sp" 
    app:expandedTitleGravity="center|bottom" 
    android:fitsSystemWindows="true"> 
    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scaleType="fitXY" 
     app:srcCompat="@drawable/bgimg" 
     app:layout_collapseMode="parallax"/> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     app:layout_anchor="@+id/MyAppbar" 
     android:layout_height="match_parent"> 
     <de.hdodenhof.circleimageview.CircleImageView 
      android:id="@+id/profile_image" 
      android:layout_width="96dp" 
      android:layout_height="96dp" 
      android:src="@drawable/studentprofile" 
      app:civ_border_width="2dp" 
      app:civ_border_color="#0adcf4" 
      android:layout_marginTop="58dp" 
      android:layout_alignParentTop="true" 
      android:layout_centerHorizontal="true" /> 

     <TextView 
      android:id="@+id/branch" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:text="Branch: " 
      android:textColor="@color/textColorPrimary" 
      android:textSize="14sp" 
      android:layout_marginBottom="20sp" 
      android:layout_alignParentBottom="true" 
      android:layout_centerInParent="true" /> 
    </RelativeLayout> 
    <android.support.v7.widget.Toolbar 
     android:id="@+id/MyToolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     app:layout_collapseMode="pin" /> 

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

に隠れています。よくやった! – Radu

0

ことは、これを試してみてください。

変更あなたのCollapsingToolbarLayoutレイアウト属性:

使用:

app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed" 

の代わりに、

app:layout_scrollFlags="scroll|exitUntilCollapsed" 

とツールバーコンポーネント

android:minHeight="?attr/actionBarSize" 

にこの属性を追加説明:宣言され、あなたがminHeightを指定した

enterAlwaysと仮定すると、あなたもenterAlwaysCollapsedを指定することができます。この設定を使用すると、ビューはこの最小の高さでのみ表示されます。トップに達するをスクロールしたときにのみビューは、その完全な高さに拡大します。詳細については、

https://guides.codepath.com/android/Handling-Scrolls-with-CoordinatorLayout

+0

は、私は同じソリューション:)をテストしていただけのようにこれを見つけ崩壊モード –

関連する問題