协调员行为ImageView [英] Coordinator Behavior ImageView

查看:69
本文介绍了协调员行为ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的CoordinatorLayout遇到了一些麻烦.当我向上滚动时,我希望图像视图完全消失.

I'm having some trouble with my CoordinatorLayout. When I scroll up I want the imageview to disappear completely.

这是视图的一个示例,在我向上滚动之后 http://imgur.com/KI8kouG

This is an example of view and after i scroll up http://imgur.com/KI8kouG

planet_main.xml

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?colorPrimary"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    >

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/ctlLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        app:titleEnabled="false"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="64dp"
            android:layout_marginRight="64dp"
            android:layout_marginTop="32dp"
            android:fitsSystemWindows="true"
            android:orientation="vertical"
            app:layout_collapseMode="parallax"
            >

            <ImageView
                android:id="@+id/userAvatar"
                android:layout_width="@dimen/fab_large"
                android:layout_height="@dimen/fab_large"
                android:layout_gravity="center_horizontal"
                android:src="@drawable/pl_alderaan"
                android:padding="2dp"
                />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                >

                <TextView
                    android:id="@+id/userLogin"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="4dp"
                    android:gravity="center_horizontal"
                    android:maxLines="1"
                    android:textSize="36sp"
                    android:text="Header"
                    android:textColor="@color/white"/>

                <TextView
                    android:id="@+id/userName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="4dp"
                    android:gravity="center_horizontal"
                    android:maxLines="1"
                    android:textSize="16sp"
                    android:textStyle="bold"
                    android:text="Subheader"
                    android:textColor="@color/white"
                    />
            </LinearLayout>
        </LinearLayout>

        <android.support.v7.widget.Toolbar
            android:id="@id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
    </android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/card"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:layout_gravity="fill_vertical">

    <TextView
        android:id="@+id/txtDescription"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="5dp"
        android:textColor="@color/text"
        android:gravity="center"
        android:text="@string/lorum"
        android:textSize="14sp"
        android:layout_margin="10dp" />


</android.support.v4.widget.NestedScrollView>

在找到一些示例之后,我也尝试实现自定义行为,尤其是通过此处,因为它可能没有被调用而不是直接的孩子如何保持布局并淡化/隐藏imageview?

I've also attempted to implement a custom behavior after finding a few examples on, especially this GitHub app example byGitskarios since our layouts are similar but it does not fix my issue. I also read Here that it may not be getting called due to it not being a direct child. How do I keep my layout and fade/hide the imageview?

推荐答案

简单的方法是在CollapsingToolbarLayout上使用app:contentScrim="@color/your_toolbar_color".从技术上讲,这不会消除图像,它只会再次用工具栏的颜色覆盖它,但看起来似乎会淡出和淡出.

The easy method is to use app:contentScrim="@color/your_toolbar_color" on the CollapsingToolbarLayout. Technically this won't get rid of the image, it will just cover it with your toolbar's color again, but it will appear to fade out and in.

这篇关于协调员行为ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆