基于 % 高度的 ImageView 背景颜色

ImageView background color based on % height

我正在设置下图中的 red 背景颜色。因此,它在整个背景中应用 red 颜色。但是现在,我想根据给定的高度应用 red 颜色,例如图像的 30% 或图像的 70%。因此,它应该只为 30% 或 70% 的高度从下到上应用颜色。我尝试使用 LinearLayout params 但它正在调整图像大小而不仅仅是背景颜色。我该怎么做?

在这里,边框的内部是透明的,边框的外部是白色的,所以它只会在内侧应用背景色。

我自己解决了这个问题。我将 RelativeLayoutViewImageView 一起使用。 View 具有背景颜色并基于高度。检查下面 xml :

<RelativeLayout
                android:layout_width="300dp"
                android:layout_height="match_parent" >

                <View
                    android:layout_width="300dp"
                    android:layout_height="150dp"
                    android:layout_alignParentBottom="true"
                    android:background="@color/red" >
                </View>

                <ImageView
                    android:layout_width="300dp"
                    android:layout_height="350dp"
                    android:src="@drawable/ic_image" />
            </RelativeLayout>