天天看點

android 畫布 透明,如何在Android中使畫布透明?

package com.logistics.kiddiekuts.Trans;

import android.content.Context;

import android.graphics.Canvas;

import android.graphics.Paint;

import android.graphics.RectF;

import android.graphics.Paint.Style;

import android.util.AttributeSet;

import android.widget.RelativeLayout;

public class TransparentPanel extends RelativeLayout {

private Paint innerPaint, borderPaint;

public TransparentPanel(Context context, AttributeSet attrs) {

super(context, attrs);

init();

}

public TransparentPanel(Context context) {

super(context);

init();

}

private void init() {

innerPaint = new Paint();

innerPaint.setARGB(225, 225, 225, 225); // gray

innerPaint.setAntiAlias(true);

borderPaint = new Paint();

borderPaint.setARGB(255, 255, 255, 255);

borderPaint.setAntiAlias(true);

borderPaint.setStyle(Style.STROKE);

borderPaint.setStrokeWidth(2);

}

public void setInnerPaint(Paint innerPaint) {

this.innerPaint = innerPaint;

}

public void setBorderPaint(Paint borderPaint) {

this.borderPaint = borderPaint;

}

protected void dispatchDraw(Canvas canvas) {

RectF drawRect = new RectF();

drawRect.set(0, 0, getMeasuredWidth(), getMeasuredHeight());

canvas.drawRoundRect(drawRect, 8, 8, innerPaint);

// canvas.drawRoundRect(drawRect, 5, 5, borderPaint);

super.dispatchDraw(canvas);

}

}

XML ::

android:text="Name :" android:textColor="#000000"

android:layout_marginLeft="15dip" android:layout_marginTop="27dip"

android:id="@+id/tvname" android:layout_height="wrap_content">

android:layout_marginLeft="7dip" android:textSize="12dip"

android:layout_marginTop="23dip" android:layout_toRightOf="@+id/tvname"

android:layout_height="35dip" />

android:text="Phone :" android:textColor="#000000"

android:layout_marginLeft="15dip" android:layout_marginTop="18dip"

android:layout_below="@+id/tvname" android:id="@+id/tvphone"

android:layout_height="wrap_content">

android:textSize="12dip" android:layout_marginLeft="5dip"

android:layout_marginTop="3dip" android:layout_toRightOf="@+id/tvphone"

android:layout_below="@+id/name" android:layout_height="35dip">

android:text="Email :" android:textColor="#000000"

android:layout_marginLeft="15dip" android:layout_marginTop="20dip"

android:layout_below="@+id/tvphone" android:id="@+id/tvemail"

android:layout_height="wrap_content">

android:textSize="12dip" android:layout_marginLeft="9dip"

android:layout_marginTop="3dip" android:layout_toRightOf="@+id/tvemail"

android:layout_below="@+id/phone" android:layout_height="35dip">

android:text="Category :" android:textColor="#000000"

android:layout_marginLeft="15dip" android:layout_marginTop="20dip"

android:layout_below="@+id/tvemail" android:id="@+id/tvcategory"

android:layout_height="wrap_content">

android:textColor="#000000" android:layout_marginLeft="10dip"

android:text="For Appointment" android:layout_marginTop="8dip"

android:layout_toRightOf="@+id/tvcategory" android:layout_below="@+id/email"

android:layout_height="wrap_content">

android:text="Location :" android:textColor="#000000"

android:layout_marginLeft="15dip" android:layout_marginTop="10dip"

android:layout_below="@+id/tvcategory" android:id="@+id/tvlocation"

android:layout_height="wrap_content">

android:textColor="#000000" android:layout_marginLeft="10dip"

android:text="Atlanta,Ga" android:layout_marginTop="10dip"

android:layout_toRightOf="@+id/tvlocation" android:layout_below="@+id/category"

android:layout_height="wrap_content">

android:textColor="#000000" android:text="Message:"

android:layout_marginLeft="15dip" android:layout_marginTop="10dip"

android:layout_below="@+id/tvlocation" android:id="@+id/tvatn"

android:layout_height="wrap_content">

android:textSize="12dip" android:lines="7" android:layout_below="@+id/tvatn"

android:layout_marginLeft="15dip" android:layout_marginTop="3dip"

android:gravity="top|left" android:layout_height="wrap_content">

android:layout_marginLeft="15dip" android:layout_marginTop="3dip"

android:id="@+id/btnsubmit" android:background="@drawable/submit_btn"

android:layout_width="250dip">

android:layout_below="@+id/btnsubmit" android:layout_height="wrap_content">