I want to make the drawing surface of my app transparent so that the my app can look like the user can draw on top of my background image, I have the following XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg2"
>
<com.almondmendoza.drawings.DrawingSurface
android:layout_width="fill_parent"
android:layout_height="200dip"
android:id="@+id/drawingSurface"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="OK"
android:onClick="onClick"
android:id="@+id/colorGreenBtn" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Scratch"
android:onClick="onClick"
android:id="@+id/开发者_运维问答colorRedBtn" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Minor Scratch"
android:onClick="onClick"
android:id="@+id/colorBlueBtn" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Dent"
android:onClick="onClick"
android:id="@+id/dentBtn" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Minor Dent"
android:onClick="onClick"
android:id="@+id/minorDentBtn" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Damaged"
android:onClick="onClick"
android:id="@+id/damagedBtn" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Undo"
android:onClick="onClick"
android:id="@+id/undoBtn" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Redo"
android:onClick="onClick"
android:id="@+id/redoBtn" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Save"
android:onClick="onClick"
android:id="@+id/saveBtn" />
</LinearLayout>
</RelativeLayout>
The ouput of the XML code above is like this:
As you can see the drawing surface is the black part of the screen. I want this to be transparent, is that possible?
Thanks a lot for any help! :)
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::
<TextView android:layout_width="wrap_content"
android:text="Name :" android:textColor="#000000"
android:layout_marginLeft="15dip" android:layout_marginTop="27dip"
android:id="@+id/tvname" android:layout_height="wrap_content"></TextView>
<EditText android:layout_width="197dip" android:id="@+id/name"
android:layout_marginLeft="7dip" android:textSize="12dip"
android:layout_marginTop="23dip" android:layout_toRightOf="@+id/tvname"
android:layout_height="35dip" />
<TextView android:layout_width="wrap_content"
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"></TextView>
<EditText android:layout_width="197dip" android:id="@+id/phone"
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"></EditText>
<TextView android:layout_width="wrap_content"
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"></TextView>
<EditText android:layout_width="197dip" android:id="@+id/email"
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"></EditText>
<TextView android:layout_width="wrap_content"
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"></TextView>
<TextView android:layout_width="wrap_content" android:id="@+id/category"
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"></TextView>
<TextView android:layout_width="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"></TextView>
<TextView android:layout_width="wrap_content" android:id="@+id/txtlocation"
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"></TextView>
<TextView android:layout_width="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"></TextView>
<EditText android:layout_width="250dip" android:id="@+id/atn"
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"></EditText>
<Button android:layout_height="25dip" android:layout_below="@+id/atn"
android:layout_marginLeft="15dip" android:layout_marginTop="3dip"
android:id="@+id/btnsubmit" android:background="@drawable/submit_btn"
android:layout_width="250dip"></Button>
<TextView android:id="@+id/text" android:layout_width="fill_parent"
android:layout_below="@+id/btnsubmit" android:layout_height="wrap_content"></TextView>
</com.logistics.kiddiekuts.Trans.TransparentPanel>
精彩评论