Android自己定義圓角ImageView

2021-09-07 11:12:38 字數 1449 閱讀 6918

package com.yulongfei.imageview;

import android.content.context;

import android.content.res.typedarray;

import android.graphics.bitmap;

import android.graphics.bitmap.config;

import android.graphics.canvas;

import android.graphics.color;

import android.graphics.paint;

import android.graphics.path;

import android.graphics.porterduff;

import android.graphics.porterduffxfermode;

import android.graphics.rectf;

import android.util.attributeset;

import android.widget.imageview;

public class roundangleimageview extends imageview

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

public roundangleimageview(context context, attributeset attrs)

private void init(context context, attributeset attrs) else

} /** 重寫draw() */

@override

public void draw(canvas canvas)

//將imageview自己繪製到canvas2上,這個導致bitmap裡面存放了imageview

super.draw(canvas2);

//利用canvas畫乙個圓角矩形,這個會改動bitmap的資料

drawroundangle(canvas2);

//將裁剪好的bitmap繪製到系統當前canvas上,這樣裁剪好的imageview就能顯示到螢幕上

paint paint = new paint();

paint.setxfermode(null);

canvas.drawbitmap(bitmap, 0, 0, paint);

bitmap.recycle();

} public void setroundwidth(int roundwidth, int roundheight)

private void drawroundangle(canvas canvas)

}

android自己定義控制項 自己定義View屬性

1 自己定義view的屬性 2 在view的構造方法中獲得我們自己定義的屬性 3 重寫onmesure 4 重寫ondraw 3這個步驟不是必須,當然了大部分情況下還是須要重寫的。1 自己定義view的屬性,首先在res values 下建立乙個attrs.xml 在裡面定義我們的屬性和宣告我們的整...

android 自定義實現圓角Dialog

首先我們需要自定義dialog布局檔案view input pwd dialog.xml,如下 dialog背景圓角定義dialog bg.xml 實現 layoutinflater inflater layoutinflater from getactivity linearlayout layo...

Android 自定義圓角 陰影布局

設定布局的圓角,將子view超出圓角的區域裁剪掉 設定陰影,不改變子view的大小,將布局大小擴充到可以容納陰影,並調整子view的位置 使用canvas.clip 方法裁剪畫圖區域 存在鋸齒,不使用 使用paint的xfermode進行處理,獲得需要效果 使用 使用viewoutlineprovi...