[英]How to make CollapsingToolbar with “wrap_content” height?
I want to make search toolbar which appears on swipe down and collapses on swipe up, regardless of scroll level. 我想使搜索工具栏在向下滑动时显示,而在向上滑动时折叠,无论滚动级别如何。 I encountered a problem when I wanted to set height of this toolbar exactly as search area.
当我想将此工具栏的高度完全设置为搜索区域时遇到问题。 On swipe down it's fine.
向下滑动就可以了。 but on swipe up search icon is still visible.
但向上滑动时,搜索图标仍然可见。
If I change AppBarLayout android:layout_height="wrap_content" to 100dp, for example, it becomes possible to hide toolbar, to but it looks bad and may cause problems on different resolutions.
例如,如果将AppBarLayout android:layout_height =“ wrap_content”更改为100dp,则可以将工具栏隐藏为,但看起来很糟糕,并且可能在不同分辨率下引起问题。 Example of what I want to achieve is search in Play Market app, how it's done there?
我要实现的示例是在Play Market应用中进行搜索,如何在其中进行搜索?
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="test.proekt101_test.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways|snap"
>
<SearchView
android:id="@+id/searchView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_marginTop="30dp"
>
</SearchView>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
Try adding android:fitsSystemWindows="true"
to SearchView
as well. 尝试将
android:fitsSystemWindows="true"
到SearchView
中。
android:fitsSystemWindows="true" is supposed to be on CoordinatorLayout, AppBarLayout, CollapsingToolbarLayout and the ImageView inside it.
android:fitsSystemWindows =“ true”应该位于CoordinatorLayout,AppBarLayout,CollapsingToolbarLayout和其中的ImageView上。
android:fitsSystemWindows=“true”
was responsible for this. 对此负责。 A useful article I've found — https://medium.com/google-developers/why-would-i-want-to-fitssystemwindows-4e26d9ce1eec#.psylrqm0y
我发现的一篇有用的文章-https: //medium.com/google-developers/why-would-i-want-to-fitssystemwindows-4e26d9ce1eec#.psylrqm0y
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.