ImageView背景颜色基于%高度

时间:2016-06-23 10:00:12

标签: android background background-color

我在下图中设置了red背景色。因此,它在完整背景中应用red颜色。但现在,我想基于给定高度应用red颜色,如图像的30%或者说70%的图像。因此,它应该从底部到顶部应用颜色仅30%或70%的高度。我尝试使用LinearLayout参数,但它正在调整图像大小而不仅仅是背景颜色。我怎么能这样做?

这里,边框的内部是透明的,边框的外侧部分是白色,因此仅在内侧应用背景颜色。

Shape

1 个答案:

答案 0 :(得分:0)

我自己解决了这个问题。我将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>