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. What did those "DO NOT MERGE" warning in the commit logs mean?

I often found those messages appeared in the ASOP commit logs, but what did
they actually mean? They indeed have been merged, otherwise I can't see
them, right?


2. mo tanya tentang bootloader

malem semua,
saya punya nexus one unlock yang bli langsung dari google. saya mau root
nexusone nya apa perlu diunlock lagi bootloader nya soalnya denger2 nexus
one yang dibeli langsung dari google sudah di unlock bootloader nya. Bisa
bantu ga kasih tau gimana cara cek bootloader sudah ke unlock ato belum.

"Indonesian Android Community [id-android]" 

3. Getting file extension of resource?

4. 2nd phone line Line2 iPhone

5. How to trigger an event if the user click on a specific area.

6. Write: apps fingerprint buat unlock screen pake sidik jari

7. eMMC and Suspend/Resume