[英]How to make rounded corners for an image?
如何使用百分比图标为图像制作圆角? 我尝试对 imageView 使用负边距,但不起作用。 谢谢。
<LinearLayout
android:gravity="center_vertical"
android:layout_marginTop="15dp"
android:layout_gravity="top|center"
android:background="@drawable/rounded_background_white"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:src="@drawable/ic_discount_percent"
android:layout_marginLeft="-3dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:textColor="@android:color/black"
android:layout_marginLeft="8dp"
android:text="Скидка 10%"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
您可以使用CircleImageView
而不是ImageView
<LinearLayout
android:gravity="center_vertical"
android:layout_marginTop="15dp"
android:layout_gravity="top|center"
android:background="@drawable/rounded_background_white"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<de.hdodenhof.circleimageview.CircleImageView
android:src="@drawable/ic_discount_percent"
android:layout_gravity="start"
android:layout_marginStart="0dp"
android:layout_width="30dp"
android:layout_height="30dp" />
<TextView
android:textColor="@android:color/black"
android:layout_marginLeft="8dp"
android:text="Скидка 10%"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
使CircleImageView
宽度和高度与 2 x 角半径相同。 没有填充。
将以下内容添加到 gradle 依赖项
implementation 'de.hdodenhof:circleimageview:3.0.0'
使用筹码
<com.google.android.material.chip.Chip
style="@style/Widget.MaterialComponents.Chip.Action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:chipIcon="@drawable/ic_action_24" // important part
android:text="@string/hello_world"/>
根据您使用的style
,您将能够创建这样的东西
在此处阅读更多信息: https : //material.io/develop/android/components/chip/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.