android - 无法将渐变设置为圆形背景或图像视图的 src
问题描述
我创建的渐变如下
<?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>
在我的 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"/>
尝试了以下链接,但渐变仍然是方形的。
关于如何实现这一点的任何帮助?
注意:我不希望以圆形创建渐变,因为我稍后会在应用程序中重复使用它
解决方案
像这样使用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>
你不再需要CircleImageView
了。
推荐阅读
- javascript - Socket.io如何实现一个wss连接?
- translation - Microsoft 翻译服务的身份验证错误
- ios - SwiftUI 无法关闭呈现的第二张工作表
- python - python如何将代码更改为递归函数
- docker-compose - 如何在 Docker compose yaml 中定义事件中心?
- linux - 错误无法连接到zsys守护进程:连接错误:desc =“传输:拨号时出错拨号unix /run/zsysd.sock:
- sql - 更新列表中的多个条件
- python - 有没有办法编写程序可以接受任何文本文件而不管布局结构的代码?
- php - var_dump 将显示什么值 echo 不会显示?(只回答一个字)
- html - Divs 在调整大小时与底部和中心对齐