Hi,

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
scaled.
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...


[code]
private class ExpandedLayout extends RelativeLayout {

                private int topRect, bottomRect, leftRect, rightRect;

                private int initTopRect, initBottomRect, initLeftRect,
initRightRect;

                private Timer viewTimer;

                private TimerTask updateMaskTask;


                public ExpandedLayout(Context context) {
                        super(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(){
                                @Override
                                public void run() {
                                        if (topRect > 0) {
                                                topRect = (topRect-1 < 0) ? 0 : 
(topRect-1);
                                        }
                                        if (bottomRect < screenHeight) {
                                                bottomRect = (bottomRect+1 > 
screenHeight) ? screenHeight :
(bottomRect+1);
                                        }
                                        if (leftRect > 0) {
                                                leftRect = (leftRect-1 < 0) ? 0 
: (leftRect-1);
                                        }
                                        if (rightRect < screenWidth) {
                                                rightRect = (rightRect+1 > 
screenWidth) ? screenWidth :
(rightRect+1);
                                        }
                                        postInvalidate();
                                        if ( (topRect == 0) && (bottomRect == 
screenHeight) && (leftRect
== 0) && (rightRect == screenWidth) ) {
                                                updateMaskTask.cancel();
                                                viewTimer.cancel();
                                                postInvalidate();
                                        }

                                }
                        };
                        viewTimer.schedule(updateMaskTask, 200,5);
                }

                public void hide() {
                        viewTimer = new Timer();
                        updateMaskTask = new TimerTask(){
                                @Override
                                public void run() {
                                        if (topRect < initTopRect) {
                                                topRect = (topRect+1 > 
initTopRect) ? initTopRect : (topRect+1);
                                        }
                                        if (bottomRect > initBottomRect) {
                                                bottomRect = (bottomRect-1 < 
initBottomRect) ? initBottomRect :
(bottomRect-1);
                                        }
                                        if (leftRect < initLeftRect) {
                                                leftRect = (leftRect+1 > 
initLeftRect) ? initLeftRect : (leftRect
+1);
                                        }
                                        if (rightRect > initRightRect) {
                                                rightRect = (rightRect-1 < 
initRightRect) ? initRightRect :
(rightRect-1);
                                        }
                                        if ( (topRect == initTopRect) && 
(bottomRect == initBottomRect)
&&
                                                         (leftRect == 
initLeftRect) && (rightRect == initRightRect)) {
                                                updateMaskTask.cancel();
                                                viewTimer.cancel();
                                        }
                                        postInvalidate();
                                }
                        };
                        viewTimer.schedule(updateMaskTask, 200,5);
                }

                @Override
                protected void onDraw(Canvas canvas) {
                        canvas.clipRect(new Rect(0, topRect, screenWidth, 
bottomRect),
Region.Op.REPLACE);
                        canvas.drawArgb(70, 127, 127, 127);
                        super.onDraw(canvas);
                }


        }
[/code]

Thanks.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to