崩溃后调整我的CollapsingToolbarLayout大小

时间:2018-04-25 06:11:11

标签: android android-collapsingtoolbarlayout

我想实现CollapsingToolbarLayout结果,如图片image所示。我在这里得到的是一张图片:I have achived it

但是,当appbar扩展时,它应该看起来像:end result。我的tablayout下面有额外的空间:what I am able to do

这是我的xml代码:

<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:id="@+id/coordinator"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.theta.animationdemo.statusbarImage.HideStatusbarActivity">

   <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="90dp"
        android:paddingTop="0dp"
        android:background="@color/colorAccent"
        android:fitsSystemWindows="true"
        android:minHeight="0dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/cToolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:expandedTitleTextAppearance="@style/CollapsingToolbarLayoutExpandedTextStyle"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_gravity="bottom"
                android:background="@color/colorPrimary">

                <ImageView
                    android:id="@+id/img1"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:clickable="true"
                    android:src="@drawable/motion" />

                <ImageView
                    android:id="@+id/img2"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:clickable="true"
                    android:src="@drawable/sparkle" />
            </LinearLayout>

            <TextView
                android:id="@+id/text"
                android:layout_width="match_parent"
                android:layout_height="20dp"
                android:layout_marginTop="2dp"
                android:text="Indiatimes"
                android:textAlignment="center" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="20dp"
                android:layout_marginTop="20dp"
                android:paddingTop="5dp"
                app:layout_collapseMode="parallax"
                app:layout_scrollFlags="scroll|enterAlways"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

                <ImageView
                    android:id="@+id/leftMenu"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="left|center_vertical"
                    android:backgroundTint="@color/whiteColor"
                    android:clickable="true"
                    android:src="@drawable/ic_close"
                    android:visibility="visible" />

                <com.theta.animationdemo.ParallaxViewPagerDemo.CircleIndicator
                    android:id="@+id/tabIndicator"
                    android:layout_marginLeft="80dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:gravity="center_horizontal"
                    app:ci_animator="@animator/indicator_no_animator"
                    app:ci_drawable="@drawable/onboarding_selected_tab"
                    app:ci_drawable_unselected="@drawable/page_unselected"
                    app:ci_height="10dp"
                    app:ci_margin="5dp"
                    app:ci_width="10dp" />

                <ImageView
                    android:id="@+id/rightMenu"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="right|center_vertical"
                    android:clickable="true"
                    android:src="@drawable/ic_close"
                    android:visibility="visible" />

            </android.support.v7.widget.Toolbar>
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>

要在折叠时更改工具栏颜色,我正在使用下面的代码。还有其他方法可以实现它!

appbar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
            int scrollRange = -1;
            @Override
            public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
                cToolbar.setTitle(" "); // not to show title
                if (scrollRange == -1) {
                    scrollRange = appBarLayout.getTotalScrollRange();
                }
                if (scrollRange + verticalOffset == 0) {
                } else {
                    cToolbar.setBackgroundColor(ContextCompat.getColor(HideStatusbarActivity.this, R.color.colorAccent));
                    cToolbar.setStatusBarScrimColor(ContextCompat.getColor(HideStatusbarActivity.this, R.color.colorAccent));
                    cToolbar.setContentScrimColor(ContextCompat.getColor(HideStatusbarActivity.this, R.color.colorAccent));
                }
            }
        });

我已经搜索了很多来达到我的要求,但我只找到了关于collapsingToolbar标题的结果。

对我来说这将是一个很好的帮助,即使有人可以提供给我链接..

0 个答案:

没有答案