當前位置:首頁 » 安卓系統 » 安卓怎麼變圓形

安卓怎麼變圓形

發布時間: 2025-10-01 15:05:17

A. 安卓imageview控制項怎麼設置成圓形

首先,定義定義圓形Imageview類:

java">
importandroid.content.Context;

importandroid.graphics.Bitmap;
importandroid.graphics.Bitmap.Config;
importandroid.graphics.Canvas;
importandroid.graphics.Color;
importandroid.graphics.Paint;
importandroid.graphics.PorterDuff.Mode;
importandroid.graphics.PorterDuffXfermode;
importandroid.graphics.Rect;
importandroid.graphics.drawable.BitmapDrawable;
importandroid.graphics.drawable.Drawable;
importandroid.util.AttributeSet;
importandroid.widget.ImageView;

{

publicRoundImageView(Contextcontext){
super(context);
//TODOAuto-generatedconstructorstub
}

publicRoundImageView(Contextcontext,AttributeSetattrs){
super(context,attrs);
}

publicRoundImageView(Contextcontext,AttributeSetattrs,intdefStyle){
super(context,attrs,defStyle);
}

@Override
protectedvoidonDraw(Canvascanvas){

Drawabledrawable=getDrawable();

if(drawable==null){
return;
}

if(getWidth()==0||getHeight()==0){
return;
}

Bitmapb=((BitmapDrawable)drawable).getBitmap();

if(null==b)
{
return;
}

Bitmapbitmap=b.(Bitmap.Config.ARGB_8888,true);

intw=getWidth(),h=getHeight();


BitmaproundBitmap=getCroppedBitmap(bitmap,w);
canvas.drawBitmap(roundBitmap,0,0,null);

}

(Bitmapbmp,intradius){
Bitmapsbmp;
if(bmp.getWidth()!=radius||bmp.getHeight()!=radius)
sbmp=Bitmap.createScaledBitmap(bmp,radius,radius,false);
else
sbmp=bmp;
Bitmapoutput=Bitmap.createBitmap(sbmp.getWidth(),
sbmp.getHeight(),Config.ARGB_8888);
Canvascanvas=newCanvas(output);

finalintcolor=0xffa19774;
finalPaintpaint=newPaint();
finalRectrect=newRect(0,0,sbmp.getWidth(),sbmp.getHeight());

paint.setAntiAlias(true);
paint.setFilterBitmap(true);
paint.setDither(true);
canvas.drawARGB(0,0,0,0);
paint.setColor(Color.parseColor("#BAB399"));
canvas.drawCircle(sbmp.getWidth()/2+0.7f,sbmp.getHeight()/2+0.7f,
sbmp.getWidth()/2+0.1f,paint);
paint.setXfermode(newPorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(sbmp,rect,rect,paint);


returnoutput;
}

}

然後在別的布局文件中使用該控制項即可,如:

<?xmlversion="1.0"encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/side_right"
android:gravity="center"
android:orientation="vertical">

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="35dip"
android:orientation="vertical">

<<spanstyle="color:#ff0000;">com.founder.reader.view.RoundImageView</span>
android:id="@+id/right_login_head"
android:layout_width="60dip"
android:layout_height="60dip"
android:scaleType="centerInside"
android:src="@drawable/user"/>
熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:713
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:980
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:687
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:840
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:747
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1086
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:314
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:194
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:882
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:841