如何适应圆形图像查看?

gha*_*deh 1 android android-imageview

我在我的应用程序中使用圆形image_View,但是当image_View图像的选择图像不适合image_View时

这个image_View:(xml)

<ImageView
        android:id="@+id/user_profile_pic"
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:layout_below="@+id/user_cover_pic"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="-60dp"
        android:background="@drawable/circular_border"
        android:elevation="6dp"
        android:scaleType="centerCrop"
        android:padding="10dp"
        android:src="@drawable/ghasem"
        tools:ignore="ContentDescription,UnusedAttribute" />
Run Code Online (Sandbox Code Playgroud)

这个圆形边界:

<

?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="100dp" />
    <solid android:color="#fff" />
    <stroke
        android:width="3dip"
        android:color="@color/colorAccent" />
    <padding
        android:bottom="4dp"
        android:left="4dp"
        android:right="4dp"
        android:top="4dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Jin*_*ose 6

如果您使用的是Android工作室,请添加此依赖项

dependencies {
...
compile 'de.hdodenhof:circleimageview:2.1.0'}
Run Code Online (Sandbox Code Playgroud)

然后在你的布局上使用它

<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/profile_image"
android:layout_width="96dp"
android:layout_height="96dp"
android:src="@drawable/profile"
app:civ_border_width="2dp"
app:civ_border_color="#FF000000"/>
Run Code Online (Sandbox Code Playgroud)

这会对你有所帮助