簡體   English   中英

如何為圖像制作圓角?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM