Bugdr0id
Bugdr0id

Reputation: 3063

Android CollapsingToolbarLayout vertical positioning of children

I am trying to setup a CollapsingToolbarLayout with multiple view, but because CollapsingToolbarLayout extends FrameLayout I cant place view in the right order.

This is what I am trying to achieve: Expanded view:

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

Collapsed View:

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

How do I place multiple views inside CollapsingToolbarLayout in vertical order (TextView A, TextView B, TextView C, SearchView), and set only the SearchView to be pinned?

Upvotes: 1

Views: 305

Answers (1)

ʍѳђઽ૯ท
ʍѳђઽ૯ท

Reputation: 16976

How do I place multiple views inside CollapsingToolbarLayout in vertical order (TextView A, TextView B, TextView C, SearchView)

You have to choose what you're good at it.

  1. Using LinearLayout and the other widgets inside with android:orientation="vertical".
  2. Using RelativeLayout and android:layout_below.
  3. Using ConstraintLayout and constraints like layout_constraintTop_toBottomOf.

set only the SearchView to be pinned?

Using app:layout_collapseMode="pin" will help to pin the SearchView at the top while scrolling the content.

P.S: You may have to place it outside of the CollapsingToolbarLayout.

Upvotes: 1

Related Questions