如何使用" wrap_content"制作CollapsingToolbar高度?

时间:2016-05-20 10:38:17

标签: android android-coordinatorlayout android-collapsingtoolbarlayout android-appbarlayout

我想制作搜索工具栏,无论滚动级别如何,都会向下滑动并在向上滑动时折叠。当我想将此工具栏的高度设置为搜索区域时遇到问题。在向下滑动它很好。但在向上滑动搜索图标仍然可见。 enter image description here 如果我更改AppBarLayout android:layout_height =" wrap_content"例如,对于100dp,可以隐藏工具栏,但它看起来很糟糕,可能会导致不同分辨率的问题。我想要实现的示例是在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>

2 个答案:

答案 0 :(得分:5)

尝试将 //jList1 = new JList(dlm); jList1.setModel(dlm); 添加到android:fitsSystemWindows="true"

  

android:fitsSystemWindows =“true”应该在CoordinatorLayout,AppBarLayout,CollapsingToolbarLayout和它内部的ImageView上。

来自here。为我工作。

答案 1 :(得分:0)

android:fitsSystemWindows=“true”

对此负责。我找到的一篇有用的文章 - https://medium.com/google-developers/why-would-i-want-to-fitssystemwindows-4e26d9ce1eec#.psylrqm0y

相关问题