天天看點

Android 圓形、圓角圖檔ImageView

圓形、圓角圖檔ImageView

當時做這個功能的時候也是從網上找的、比較好用的demo

作者以及詳解請見:Android BitmapShader 實戰 實作圓形、圓角圖檔

在這裡主要講一下怎樣使用

1、把RoundImageView導入包下

2、在xml中配置

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:yqy="http://schemas.android.com/apk/res/com.yqy.yqy_roundimg"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <com.yqy.yqy_roundimg.RoundImageView
        android:id="@+id/imageView1"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:layout_marginLeft="48dp"
        android:layout_marginTop="46dp"
        android:src="@drawable/logo" />

    <com.yqy.yqy_roundimg.RoundImageView
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:layout_marginLeft="48dp"
        android:layout_marginTop="46dp"
        android:src="@drawable/logo"
        yqy:borderRadius="15dp"
        yqy:type="round" />

    <com.yqy.yqy_roundimg.RoundImageView
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:layout_marginLeft="48dp"
        android:layout_marginTop="46dp"
        android:src="@drawable/logo"
        yqy:borderRadius="10dp"
        yqy:type="round" />

    <com.yqy.yqy_roundimg.RoundImageView
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:layout_marginLeft="48dp"
        android:layout_marginTop="46dp"
        android:src="@drawable/logo"
        yqy:borderRadius="5dp"
        yqy:type="round" />

</LinearLayout>      

預設就是圓形圖檔

假設想要設定圓角矩形

看上面代碼的頭部有例如以下代碼

xmlns:yqy=<a target=_blank href="http://schemas.android.com/apk/res/com.yqy.yqy_roundimg">http://schemas.android.com/apk/res/com.yqy.yqy_roundimg</a>      

設定一個屬性yqy為自己定義。值最後為包名

控件代碼中設定例如以下屬性

yqy:borderRadius="15dp"
        yqy:type="round"