首页 > 解决方案 > Android CollapsingToolbarLayout 垂直定位子项

问题描述

我正在尝试设置CollapsingToolbarLayout具有多个视图的视图,但由于CollapsingToolbarLayout扩展FrameLayout我无法以正确的顺序放置视图。

这就是我想要实现的目标: 扩展视图:

_____________________________
|Title toolbar               x|
|TextView A                   |
|TextView B                   |
|TextView C                   |
|SearchView                   |
|-----------------------------|
|RecyclerView content         |
|...                          |
|...                          |
|...                          |
|...                          |
|...                          |
|...                          |
|_____________________________|

折叠视图:

 _____________________________
|Title toolbar               x|
|SearchView                   |
|-----------------------------|
|RecyclerView content         |
|...                          |
|...                          |
|...                          |
|...                          |
|...                          |
|...                          |
|...                          |
|...                          |
|...                          |
|_____________________________|

如何CollapsingToolbarLayout以垂直顺序(TextView A, TextView B, TextView C, SearchView)将多个视图放置在内部,并仅将 SearchView 设置为固定?

标签: androidandroid-collapsingtoolbarlayout

解决方案


如何CollapsingToolbarLayout按垂直顺序放置多个视图(TextViewA、TextViewB、TextViewC、SearchView

你必须选择你擅长的。

  1. 使用LinearLayout和里面的其他小部件android:orientation="vertical"
  2. 使用RelativeLayoutandroid:layout_below
  3. 使用ConstraintLayout和约束,如layout_constraintTop_toBottomOf.

只设置SearchView要固定的?

使用app:layout_collapseMode="pin"将有助于SearchView在滚动内容时将其固定在顶部。

PS:您可能必须将其放在CollapsingToolbarLayout.


推荐阅读