How to keep transparency through canvas redraw

by isa550 » Fri, 25 Feb 2011 12:58:13 GMT

Sponsored Links

I need a layout to open with an effect of expanding opening. The
layout grows until it takes the whole screen, but the content is not
So I make a layout, override the onDraw, clipRect with a Rect that
grows with a timer.
Until there it works.
But once the layout is fully expanded, it redraws because it contains
a webview with javascript animation. In the "background" of my layout,
I have drawn a slight gray overlay or background using:
canvas.drawArgb(70, 127, 127, 127) method in onDraw().
The problem is, since onDraw() is called again, the background goes
darker, until it is completely gray, it looses its transparency.

I don't manage to avoid this problem.

If I put a background to the layout, it is shown on the whole layout
as soon as it is drawn, so the clipRect does not affect the
background, this is not the behaviour I need...

private class ExpandedLayout extends RelativeLayout {

private int topRect, bottomRect, leftRect, rightRect;

private int initTopRect, initBottomRect, initLeftRect,

private Timer viewTimer;

private TimerTask updateMaskTask;

public ExpandedLayout(Context context) {
topRect = 0;
bottomRect = screenHeight;

public void setBounds(int topInit, int bottomInit, int
leftInit, int
rightInit) {
topRect = topInit;
bottomRect = bottomInit;
leftRect = leftInit;
rightRect = rightInit;

initTopRect= topInit;
initBottomRect = bottomInit;
initLeftRect= leftInit;
initRightRect = rightInit;

public void show() {
viewTimer = new Timer();
updateMaskTask = new TimerTask(){
public void run() {
if (topRect > 0) {
topRect = (topRect-1 < 0) ? 0 :
if (bottomRect < screenHeight) {
bottomRect = (bottomRect+1 >
screenHeight) ? screenHeight :
if (leftRect > 0) {
leftRect = (leftRect-1 < 0) ? 0
: (leftRect-1);
if (rightRect < screenWidth) {
rightRect = (rightRect+1 >
screenWidth) ? screenWidth :
if ( (topRect == 0) && (bottomRect ==
screenHeight) && (leftRect
== 0) && (rightRect == screenWidth) ) {

Other Threads

1. Adding, Editing, Deleting entries in Androids call log

Here is the code I have


This works in that the logcat shows that its adding the duration, however
problems include:

Not getting the phonenumber, this gives a uncaughtexception error

And the emulator crashes the Call Log app thats already on the device when
it is used after my app has run


2. Andoird on x86 Recompile with -Xlint:unchecked for details issue

You need to pick up the opencore patch from the download section of You only need to donut patch


3. Milestone UK on sale di web SG??

4. BaseAdapter doesn't return position correctly

5. Nubie numpang tanya

6. Aplikasi iseng hari ini

7. button Click event inside custom listview.... Help!