[英]Cannot set gradient as a circle background or src to an image view
The gradient I have created it is as follows 我创建的渐变如下
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="45"
android:dither="true"
android:endColor="#00cff7"
android:startColor="#0095bf" />
</shape>
In my XML file, I want this gradient to be visible as a circle. 在我的XML文件中,我希望此渐变显示为圆形。
I have tried the following but the gradient appears as a square. 我尝试了以下方法,但渐变显示为正方形。 I tried the following third party library but the gradient is not visible.
我尝试了以下第三方库,但渐变不可见。
XML XML
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/profile_image"
android:layout_width="96dp"
android:layout_height="96dp"
android:src="@drawable/blue_bg"
app:civ_border_width="2dp"
app:civ_border_color="#FF000000"/>
Tried the following link but still, the gradient is square. 尝试了以下链接,但渐变仍然是正方形。
Any help on how this can be achieved? 如何实现这一目标的任何帮助?
Note: I don't want the gradient to be created in a circular shape as I'm reusing it later in the app 注意:我不希望将渐变创建为圆形,因为稍后我会在应用程序中重复使用它
Use CardView
like this: 像这样使用
CardView
:
<android.support.v7.widget.CardView
app:cardCornerRadius="192dp"
android:backgroundTint="@color/colorPrimary"
android:layout_width="96dp"
android:layout_height="96dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
</android.support.v7.widget.CardView>
You don't need CircleImageView
anymore. 您不再需要
CircleImageView
。
You don't have specified the shape : 您尚未指定形状:
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size
android:width="120dp"
android:height="120dp"/>
</shape>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.