android開發之自定義圓形ImagView

2021-09-08 01:30:37 字數 1165 閱讀 4649

在日常使用中我們經常會使用到圓形的,但是android系統中並沒有預設的圓形控制項,所以我們需要自己來寫乙個自定義的ima**iew來顯示一張圓形的,下面先看效果

詳細的方法是我們自定義乙個類,繼承ima**iew,然後重寫一些方法,下面是**

/**

* 圓形的ima**iew

* * @author administrator

* */

public class roundimageview extends imageview

public roundimageview(context context, attributeset attrs)

public roundimageview(context context, attributeset attrs, int defstyle)

@override

protected void ondraw(canvas canvas)

if (getwidth() == 0 || getheight() == 0)

bitmap b = ((bitmapdrawable) drawable).getbitmap();

if (null == b)

bitmap bitmap = b.copy(config.argb_8888, true);

int w = getwidth(), h = getheight();

bitmap roundbitmap = getcroppedbitmap(bitmap, w);

canvas.drawbitmap(roundbitmap, 0, 0, null);

}public static bitmap getcroppedbitmap(bitmap bmp, int radius)

}

然後在布局中引用這個自定義的控制項, 就可以了

《裡面的是你的包名加自定義的類名,如果按住ctrl+滑鼠左鍵能進入類的話,就說明引用成功了。

android:layout_centerinparent="true"

android:src="@mipmap/a8"

android:layout_width="300dp"

android:layout_height="300dp"

/>

這樣就可以了

Android自定義View之圓形頭像

圓形頭像是我們在開發中經常用到的控制項,下面我們就來自定義這樣乙個控制項 1.自定義circleimageview類繼承imageview package com.example.qw.circleimageview created by quwei on 2015 5 13 0013.import...

android開發之自定義dialog

很多時候,系統生成的dialog無法滿足我們的需求,這個時候,我們就只能自己去自定義乙個dialog來滿足自己的需要了。設定dialog 雙按鈕 private void showdialog string str1,string str2 確定按鈕 button btnok button layo...

Android開發之自定義動畫

android開發之動畫 北京android俱樂部群 167839253 created on 2011 8 23 author blueeagle email liujiaxiang gmail.com 總結一下關於android開發下的自定義動畫,主要是四個方面,尺寸,透明度,位置變化和旋轉。動...