android - 在 CordinatorLayout 中的 ImageView 底部添加阴影

标签 android imageview material-design textcolor android-coordinatorlayout

最近,我正在为我现有的应用程序实现 Material 设计。为此,我使用以下库:http://android-developers.blogspot.com/2015/05/android-design-support-library.html实现如下效果:https://plus.google.com/+AndroidDevelopers/posts/XUDGFS9eYxg .

我的布局代码如下:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

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

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginBottom="32dp"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:id="@+id/event_image"
                android:layout_width="fill_parent"
                android:layout_height="350dp"
                android:background="@color/white"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/anim_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/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.support.v4.widget.NestedScrollView>

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="30dp"
        android:clickable="true"
        android:src="@drawable/ic_action_share"
        app:layout_anchor="@+id/appbar"
        app:layout_anchorGravity="bottom|right|end" />

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

我达到了预期的效果,但图像和文本有问题。文本是白色的,当碰巧我有一张大部分由白色组成的图像时,无法读取文本标签。

有什么建议可以在不破坏效果的情况下解决吗?

最佳答案

感谢@m vai 给我的提示,我使用了另一种方法。我创建了一个 FrameLayout 并在里面放置了 ImageView 和 GradientView。然后我将所有动画属性传递给 FrameLayout。最后很简单。因此,ImageView 应该是以下代码:

  <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_collapseMode="parallax"
                android:fitsSystemWindows="true">

                <RelativeLayout
                    android:id="@+id/title_layout"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content">

                    <ImageView
                        android:id="@+id/event_image"
                        android:layout_width="fill_parent"
                        android:layout_height="350dp"
                        android:background="@color/white"
                        android:scaleType="centerCrop"
                       />

                </RelativeLayout>

                <View
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/actionbar_overlay" />
            </FrameLayout>

XML 文件如下:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">

    <size android:height="100dp"/>

    <gradient
        android:angle="270"
        android:startColor="#0000"
        android:endColor="#b000"/>

</shape>

关于android - 在 CordinatorLayout 中的 ImageView 底部添加阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31069809/

相关文章:

android 应用程序速度/帧率?

java - 如何退出包含Java的Callable ExecutiorService MultiThreading的循环(Android)

android - 使用远程计算机构建 Android 应用程序

android - 将 Uris 数组添加到 GridView 中

c# - WPF Material Design 按钮悬停

android - listview 出现内存不足异常,但没有内存泄漏?

android - 拖动时跳转 ImageView。 getX() 和 getY() 值在跳跃

android - 在特定时间在imageview中设置图像

android - 为什么我不能在 Theme.Appcompat 中使用 TextInputLayout(来自支持设计库)

Android以编程方式设置正常状态栏