我正在嘗試在 cardview 中添加影像,可以從左下角修剪一點點,以便可以形成與影像相同的半圓形。請幫助我,因為我不知道該怎么做?

uj5u.com熱心網友回復:
它只是一個帶有白色筆劃的圓形影像,如您在此影像中所見
您可以使用 ShapeableImageView 使您的影像成為圓形并向其添加筆劃,您的代碼將如下所示
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!--your main image-->
<ImageView
android:id="@ id/imageView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:src="@color/black"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!--your circular image-->
<com.google.android.material.imageview.ShapeableImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:padding="8dp"
android:src="@drawable/ic_launcher_background"
android:layout_marginTop="-40dp"
android:layout_marginStart="20dp"
app:layout_constraintStart_toStartOf="@ id/imageView"
app:layout_constraintTop_toBottomOf="@ id/imageView"
app:strokeWidth="8dp"
app:strokeColor="@color/white"
app:shapeAppearanceOverlay="@style/circleImageViewStyle"/>
</androidx.constraintlayout.widget.ConstraintLayout>
這是circleImageViewStyle, 在themes.xml檔案中
<style name="circleImageViewStyle" >
<item name="cornerFamily">rounded</item>
<item name="cornerSize">50%</item>
</style>
上面代碼的結果是這樣的
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/342357.html
