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" 

borderRadius 爲圓角半徑

type  爲round  圓角矩形
yqy:borderRadius="15dp"yqy:borderRadius="15dp"


 

發佈了62 篇原創文章 · 獲贊 5 · 訪問量 12萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章