Android - CircularImageView

摘要:Android - CircularImageView

需要做一個圓形的ImageView,

應該網路上不少GitHub提供

https://github.com/lopspower/CircularImageView

 

我就搬移了我需要的CircularImageView

https://github.com/lopspower/CircularImageView/blob/master/CircularImageView/src/com/mikhaellopez/circularimageview/CircularImageView.java

 

接著需要在attrs.xml加入


    <declare-styleable name="CircularImageView">
        <attr name="border" format="boolean"></attr>
        <attr name="border_width" format="dimension"></attr>
        <attr name="border_color" format="color"></attr>
        <attr name="shadow" format="boolean"></attr>
    </declare-styleable>
    
    <declare-styleable name="Theme">
        <attr name="circularImageViewStyle" format="reference"></attr>
    </declare-styleable>

再到layout的xml加入


	    <pagename.CircularImageView
	        android:id="@+id/logo"
	        android:layout_width="77dp"
	    	android:layout_height="77dp"
	    	android:layout_marginTop="5dp"
	    	android:layout_marginBottom="5dp"
	    	android:layout_marginRight="5dp"
	    	android:layout_marginLeft="5dp"
	    	android:scaleType="centerCrop"
	    	circular:border="false">
	   </pagename.CircularImageView>

但這xml的root節點需要加入


xmlns:circular="http://schemas.android.com/apk/res-auto"