Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8018497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:08:35+00:00 2026-06-04T21:08:35+00:00

I have a MenuView ViewGroup which capsules all the buttons of my interface. On

  • 0

I have a MenuView ViewGroup which capsules all the buttons of my interface.
On start of the app all buttons are positioned via button.layout(). Then I hide all buttons, with one exception: the menu button. When I am pressing the menu button, all other buttons are shown (via a zoom animation).

Now the problem: while positioning the buttons via button.layout(), they are visible. So almost 1 sec all buttons are shown on startup of the app.

How can I avoid that?

My button code:

public class CircleButton extends Button {

    static final int StateDefault = 0;
    static final int StateFocused = 1;
    static final int StatePressed = 2;


    private Bitmap mBitmapDefault;

    private String mCaption;
    protected int radius;
    protected int color = 0xff000000;
    private Typeface font1;
    private boolean visible = true;
    private int savedLeft, savedTop;
    // indicates whether the button is visible when the menu is rendered
    public boolean visibleInMenu = true;
    private Paint paint;
    private static String TAG = "CircleButton";

    public int getRadius(){
        return radius;
    }


    public CircleButton setRadius(int radius){
        this.radius = radius;
        this.setWidth(2*radius);
        this.setHeight(2*radius);
        return this;
    }

    public CircleButton setColor(int color){
        this.color = color;
        return this;
    }

    public CircleButton setCaption(String caption){
        mCaption = caption;
        return this;
    }
    public CircleButton(Context context) {
        super(context);
        init(context);
    }

    public CircleButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public CircleButton(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context);
    }

    private void init(Context context) {
        setClickable(true);
        setBackgroundColor(0x00000000);

        paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setStyle(Paint.Style.FILL);
        font1 = Typeface.createFromAsset(context.getAssets(), "fonts/Bebas/BEBAS___.ttf");
        mCaption = "Caption";
        this.setRadius(45);
        this.setTextSize(18);

        setOnClickListener(onClickListener);
        setOnTouchListener(onTouchListener);
    }

    public void setVisibility(int visibility) {
        if(visibility == GONE){
            this.visible = false;
        }else{
            this.visible = true;
        }
        super.setVisibility(visibility);
    }
    /**
     * draws the normal button (without rollover)
     * @param canvas
     */
    protected void drawDefault(Canvas canvas){
        //canvas.drawARGB(255, 255, 0, 0);
        Paint paintText = new Paint();
        paintText.setAntiAlias(true);
        paintText.setTextSize(this.getTextSize());
        paintText.setColor(0xffffffff); // white
        paintText.setTypeface(this.font1);

        Rect bounds = new Rect();
        //Paint textPaint = this.getPaint();
        paintText.getTextBounds(mCaption,0,mCaption.length(),bounds);

        float left = (float) (2*radius-bounds.width())/2;
        float top = (float) radius+bounds.height()/2;
        //Log.v("Button","bounds:"+bounds.width()+"x"+bounds.height());
        //Log.v("Button","this.getWIdth:"+2*radius);
        // create the Drawing Tool (Brush)
        Paint paint = new Paint();
        paint.setAntiAlias(true); // for a nicer paint

        paint.setColor(color);
        paint.setStrokeWidth(1);
        paint.setStyle(Style.FILL);

        Path path = new Path();
        path.addCircle(radius, radius, radius, Path.Direction.CW);
        canvas.drawPath(path, paint);

        canvas.save(); 
        canvas.rotate(-45,this.getRadius(),this.getRadius());
        canvas.drawText(mCaption, left, top, paintText);
        canvas.restore();
    }



    protected Bitmap getDefaultBitmap(){
        if(mBitmapDefault == null){
            mBitmapDefault = Bitmap.createBitmap(2*radius, 2*radius, Config.ARGB_8888);
            Canvas canvas = new Canvas(mBitmapDefault);
            this.drawDefault(canvas);
            return mBitmapDefault;
        }
        return mBitmapDefault;
    }




    @Override
    protected void onDraw(Canvas canvas) {
        //Log.v("Button","onDraw(): "+this.getWidth()+"x"+this.getHeight());
        super.onDraw(canvas);
        canvas.drawBitmap(this.getDefaultBitmap(), 0, 0, paint);
        //super.onDraw(canvas);
        //canvas.drawBitmap(this.getDefaultBitmap(), new Rect(0, 0, this.radius*8, this.radius*8), new Rect(0,0, this.radius*2, this.radius*2), null);
    }


    public void recycle() {
        if(mBitmapDefault != null){
            mBitmapDefault.recycle();
            mBitmapDefault = null;
        }
    }

    public void hide(){
        this.hide(true);
    }
    public void hide(boolean withAnimation){
        if(this.visible == true){
            savedLeft = getLeft();
            savedTop = getTop();

            ScaleAnimation anim = new ScaleAnimation(1, 0, 1, 0, this.getRadius(), this.getRadius());
            anim.setDuration(300);
            anim.setFillAfter(true);
            anim.setAnimationListener(new AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {}
                @Override
                public void onAnimationRepeat(Animation animation) {}

                @Override
                public void onAnimationEnd(Animation animation) {
                    visible = false;
                    layout(0, 0, 0, 0);
                }
            });
            this.startAnimation(anim);

        }

    }

    public void show(){
        if(this.visible == false){
            this.setVisibility(VISIBLE);
            OvershootInterpolator inter = new OvershootInterpolator();
            ScaleAnimation anim = new ScaleAnimation(0, 1, 0, 1, this.getRadius(), this.getRadius());
            anim.setDuration(300);
            anim.setInterpolator(inter);
            anim.setFillAfter(true);
            anim.setAnimationListener(new AnimationListener() {

                @Override
                public void onAnimationStart(Animation animation) { }

                @Override
                public void onAnimationRepeat(Animation animation) { }

                @Override
                public void onAnimationEnd(Animation animation) {
                    visible = true;

                }
            });
            this.startAnimation(anim);

            this.layout(this.savedLeft, this.savedTop, this.savedLeft+2*this.radius, this.savedTop+2*this.radius);
        }
        this.visible = true;
    }


    public CircleButton setOnClickCallback(OnClickListener l) {
        super.setOnClickListener(l);
        return this;
    }
    private OnClickListener onClickListener = new OnClickListener() {
        @Override
        public void onClick(View arg0) {

        }
    };

    private OnTouchListener onTouchListener = new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            //Log.v("Button","onTouch()");
            if(event.getAction() == MotionEvent.ACTION_DOWN){
                OvershootInterpolator inter = new OvershootInterpolator();
                ScaleAnimation anim = new ScaleAnimation(1, (float) 1.5, 1,(float) 1.5, CircleButton.this.getRadius(), CircleButton.this.getRadius());
                anim.setInterpolator(inter);
                anim.setDuration(200);
                anim.setFillAfter(true);
                CircleButton.this.startAnimation(anim);
            }else if(event.getAction() == MotionEvent.ACTION_UP){
                ScaleAnimation anim = new ScaleAnimation((float) 1.5, 1, (float) 1.5, 1, CircleButton.this.getRadius(), CircleButton.this.getRadius());
                anim.setDuration(300);
                anim.setFillAfter(true);
                CircleButton.this.startAnimation(anim);
            }
            return false;
        }
    };
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:08:36+00:00Added an answer on June 4, 2026 at 9:08 pm

    Use setVisibility(int visibility) method on the object to hide it with Parameter visibility One of VISIBLE, INVISIBLE, or GONE:

    GONE

    This view is invisible, and it doesn’t take any space for layout purposes. Use with setVisibility(int) and android:visibility.
    Constant Value: 8 (0x00000008)

    INVISIBLE

    This view is invisible, but it still takes up space for layout purposes. Use with setVisibility(int) and android:visibility.
    Constant Value: 4 (0x00000004)

    VISIBLE

    This view is visible. Use with setVisibility(int) and android:visibility.
    Constant Value: 0 (0x00000000)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
Have deployed numerous report parts which reference the same view however one of them
have been trying couple of hours now to make my iphone app universal. The
In my app, I have a loading view that sets up the app by
I have constructed the following query using NHibernate which will give me a collection
I have an atypical iOS interface. Perhaps it's not practical but I'm giving it
I have a main menu screen in my app, so that when i hit
Dear friends, I have created one music app. It contains some collection of albums,
I have a tabBar application with a menu that is called up via a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.