Android 如何为图像创建圆角?
如何为带有百分比图标的图像制作圆角?我尝试为imageView使用负边距,但不起作用。ThxAndroid 如何为图像创建圆角?,android,imageview,Android,Imageview,如何为带有百分比图标的图像制作圆角?我尝试为imageView使用负边距,但不起作用。Thx <LinearLayout android:gravity="center_vertical" android:layout_marginTop="15dp" android:layout_gravity="top|center" android:background=
<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>
使用芯片
<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"/>
根据您使用的样式
,您将能够创建类似的内容
阅读此处的更多信息:第一张图像是您想要的结果吗?如果否,请分享所需结果。是。第一个图像是期望的结果。
<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"/>