android – 停止滚动CollapsingToolbarLayout,所以它不会完全崩溃

前端之家收集整理的这篇文章主要介绍了android – 停止滚动CollapsingToolbarLayout,所以它不会完全崩溃前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个CollapsingToolbarLayout设置,并将墙纸放在那里.我想能够阻止它一塌糊涂.

我已经尝试了很高的等等,但不能弄清楚.

我怎么能让它停止崩溃第二个屏幕截图?

查看何时加载活动

所需停止点

当前停止点

解决方法

CollapsingToolbarLayout与工具栏工作非常紧密,因此折叠的高度取决于工具栏.

我可以使用这种布局解决你的问题(注意它进入正常的CoordinatorLayout / AppBarLayout安装程序,使用Fab和NestedScrollView或RecyclerView):

  1. <android.support.design.widget.CollapsingToolbarLayout
  2. android:id="@+id/collapsing_toolbar"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:fitsSystemWindows="true"
  6. app:layout_scrollFlags="scroll|exitUntilCollapsed"
  7. app:statusBarScrim="?attr/colorPrimaryDark"
  8. app:contentScrim="@android:color/transparent"
  9. app:titleEnabled="false"
  10. >
  11. <!-- There isnt a contentSCrim attribute so the toolbar is transparent after being
  12. collapsed
  13. Disabled the title also as you wont be needing it -->
  14.  
  15. <ImageView
  16. android:id="@+id/image_v"
  17. android:layout_width="match_parent"
  18. android:layout_height="360dp"
  19. android:layout_gravity="center"
  20. android:scaleType="centerCrop"
  21. android:src="@drawable/md2"
  22. android:fitsSystemWindows="true"
  23. app:layout_collapseMode="parallax"
  24. tools:ignore="ContentDescription"
  25. />
  26. <!-- Normal Imageview. Nothing interesting -->
  27.  
  28. <android.support.v7.widget.Toolbar
  29. android:id="@+id/toolbar"
  30. android:layout_width="match_parent"
  31. android:layout_height="168dp"
  32. app:layout_collapseMode="pin"
  33. app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
  34. />
  35. <!-- The toolbar is styled normally. However we disable the title also in code.
  36. Toolbar height is the main component that determines the collapsed height -->
  37.  
  38. <TextView
  39. android:text="@string/app_name"
  40. android:layout_width="match_parent"
  41. android:layout_height="wrap_content"
  42. android:layout_gravity="bottom"
  43. android:background="?attr/colorPrimaryDark"
  44. android:paddingLeft="72dp"
  45. android:paddingRight="0dp"
  46. android:paddingBottom="24dp"
  47. android:paddingTop="24dp"
  48. android:textColor="@android:color/white"
  49. android:textAppearance="@style/TextAppearance.AppCompat.Headline"
  50. />
  51. <!-- The title textView -->
  52.  
  53. </android.support.design.widget.CollapsingToolbarLayout>

相关活动如下所示:

  1. ...
  2. setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
  3. getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  4.  
  5. // Disable toolbar title
  6. getSupportActionBar().setDisplayShowTitleEnabled(false);
  7. ...

这是一个互动视频

猜你在找的Android相关文章