Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何为图像创建圆角?_Android_Imageview - Fatal编程技术网

Android 如何为图像创建圆角?

Android 如何为图像创建圆角?,android,imageview,Android,Imageview,如何为带有百分比图标的图像制作圆角?我尝试为imageView使用负边距,但不起作用。Thx <LinearLayout android:gravity="center_vertical" android:layout_marginTop="15dp" android:layout_gravity="top|center" android:background=

如何为带有百分比图标的图像制作圆角?我尝试为imageView使用负边距,但不起作用。Thx

 <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"/>