简体   繁体   中英

How can I get oval photos like Google+ app?

I'm trying to get an oval photo like the ones that uses the Google+ app to show photos of the users.

I have an ImageView like this:

        <ImageView 
            android:id="@+id/iv_user_photo"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:background="@drawable/user_photo_shape"/>

And the background drawable is this:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<solid android:color="#FFFFFF" />
<stroke android:width="1dp" android:color="#000000" />
<padding android:left="1dp" android:top="1dp" android:right="1dp" android:bottom="1dp" />
    </shape>

My problem is that when I set the image to the ImageView with setImageBitmap, the rectangle image is painted OVER the background and it's not limited to the oval border. I've tried with "AdjustViewBounds=true" but it doesn't change anything. Do you know how can I achieve this?

我刚刚使用Romain Guy博客的这篇帖子中的代码找到了一个解决方案。

I haven't done this before, but this link shows how to mask off using PorterDuffXfermode.

PorterDuffXfermode

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM