簡體   English   中英

如何將畫廊中選定的圖像塑造成圓形

[英]how can I shape Circular the selected image from gallery

如何擁有一個curcular ImageView。 這是我的 xml

<RelativeLayout
            android:id="@+id/imgUser"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="20dp"
            android:background="@drawable/circle_border">

            <ImageView
                android:id="@+id/studentimg"
                android:layout_width="120dp"
                android:layout_height="120dp"
                android:layout_margin="9dp"
                android:adjustViewBounds="true"
                android:background="@drawable/circlepf"
                android:padding="3dp"
                android:scaleType="centerInside"
                android:src="@drawable/ic_profile" />
</RelativeLayout>

這是我的問題圖像樣本

1

但我希望這張圖片以circular view

您可以使用材料組件庫
版本1.2.0-alpha03有新的ShapeableImageView

  <com.google.android.material.imageview.ShapeableImageView
      ...
      android:scaleType="centerInside"
      android:adjustViewBounds="true"
      app:shapeAppearanceOverlay="@style/circleImageView"
      app:srcCompat="@drawable/ic_profile" />

和:

  <style name="circleImageView" parent="">
    <item name="cornerFamily">rounded</item>
    <item name="cornerSize">50%</item>
  </style>

在此處輸入圖片說明

我最近在 Github 上發現了這個庫。 https://github.com/christophesmet/android_maskable_layout

任何包裝在 MaskableFrameLayout 中的布局或圖像視圖都將被裁剪成所需的形狀,只需向 maskLayout 的 mask 屬性提供所需的形狀,如下所示:

<com.christophesmet.android.views.maskableframelayout.MaskableFrameLayout
    android:id="@+id/frm_mask_animated"
    android:layout_width="100dp"
    app:porterduffxfermode="DST_IN"
    app:mask="@drawable/drawable_circular"
    android:layout_height="100dp">

    <ImageView android:layout_width="match_parent"
               android:layout_height="match_parent"
               android:scaleType="centerCrop"
               android:src="@drawable/unicorn"/>

</com.christophesmet.android.views.maskableframelayout.MaskableFrameLayout>

此外,您有可用的 Circleimageview 庫: https : //github.com/hdodenhof/CircleImageView

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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