How to add a gradient to a ImageView nested in a CollapsingToolbar

前端 未结 1 722
说谎
说谎 2020-12-10 04:32

I\'am working on an Android app with material design. I have a detail view with a CollapsingToolbarLayout and a ImageView (works fine so far). Unfortunately the title is not

相关标签:
1条回答
  • 2020-12-10 04:51

    Wrap your ImageView in a FrameLayout and add a View with a background:

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <ImageView
            android:id="@+id/backimg"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:layout_collapseMode="parallax"
            android:scaleType="centerCrop"
            android:src="@drawable/image"
            app:layout_scrollFlags="scroll|enterAlways" />
        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/actionbar_gradient_dark" />
    </FrameLayout>
    

    Make sure your gradient is something like this:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle" >
        <gradient
            android:angle="90"
            android:endColor="@android:color/transparent"
            android:startColor="@android:color/black" />
        <corners android:radius="0dp" />
    </shape>
    
    0 讨论(0)
提交回复
热议问题