如何设置背景图像形状?
How to set background image to shape?
我有一个形状。我正在使用随机颜色来填充形状。
我有一张图片需要设置为这个形状的背景。 (我只是觉得应该是背景,可能是我用错词了。)
结果应该是这样的(注意背景中的图像)。
我推荐你那个库,你可以自定义角、形状和其他东西,然后你可以把你的图像视图放在里面,然后你就会有你的视图
您可以将您的图像视图的 src 设置为您拥有的那些白色东西,然后您将以您的形状作为背景,上面还有这个图案。
使用 android:src
我遇到了这个库。 RoundedImageView
Github link
我需要做的就是:
<com.makeramen.roundedimageview.RoundedImageView
android:layout_width="0dp"
android:layout_height="200dp"
android:src="@drawable/add_card_head_bg"
android:scaleType="centerCrop"
app:riv_corner_radius="90dip"
app:riv_mutate_background="true"
app:riv_corner_radius_bottom_left="50dp"/>
如果您想在形状内显示图像,试试这个,
shape.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/colorPrimaryDark"/>
<corners android:bottomLeftRadius="56dp"/>
</shape>
现在设置 layout 的形状,然后在图像视图中添加您想要的图像,然后调整 alpha 值以显示形状和图像,
layout.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:background="@drawable/shape">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/blue_image"
android:alpha=".2"/>
</RelativeLayout>
Output will be like this
希望这会有所帮助。
我有一个形状。我正在使用随机颜色来填充形状。
我有一张图片需要设置为这个形状的背景。 (我只是觉得应该是背景,可能是我用错词了。)
结果应该是这样的(注意背景中的图像)。
我推荐你那个库,你可以自定义角、形状和其他东西,然后你可以把你的图像视图放在里面,然后你就会有你的视图
您可以将您的图像视图的 src 设置为您拥有的那些白色东西,然后您将以您的形状作为背景,上面还有这个图案。 使用 android:src
我遇到了这个库。 RoundedImageView
Github link
我需要做的就是:
<com.makeramen.roundedimageview.RoundedImageView
android:layout_width="0dp"
android:layout_height="200dp"
android:src="@drawable/add_card_head_bg"
android:scaleType="centerCrop"
app:riv_corner_radius="90dip"
app:riv_mutate_background="true"
app:riv_corner_radius_bottom_left="50dp"/>
如果您想在形状内显示图像,试试这个,
shape.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/colorPrimaryDark"/>
<corners android:bottomLeftRadius="56dp"/>
</shape>
现在设置 layout 的形状,然后在图像视图中添加您想要的图像,然后调整 alpha 值以显示形状和图像,
layout.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="120dp"
android:background="@drawable/shape">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/blue_image"
android:alpha=".2"/>
</RelativeLayout>
Output will be like this
希望这会有所帮助。