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 8206639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:44:43+00:00 2026-06-07T08:44:43+00:00

i have two buttons put in line inside layout. i d’ like them to

  • 0

i have two buttons put in line inside layout. i d’ like them to have the same width. but width of every button have to be equal the widest of them. now i use ViewTreeObserver.

    class LayoutListener implements ViewTreeObserver.OnGlobalLayoutListener{
    private Button btn1, btn2;

    public LayoutListener(Button b1, Button b2){
        btn1 = b1; btn2 = b2;
    }
    @Override
    public void onGlobalLayout() {
        int w1 = btn1.getWidth();
        int w2 = btn2.getWidth();
        if (w1 < w2)
            btn1.setWidth(w2);
        else
            btn2.setWidth(w1);
    }
}

but it’s not good decision becase elements are redrawn after they was shown to the user and it looks terrible.
and question as you can guess, how can i reach needed behavior? is there way of markup manipulating or i should implement special code? it’s desirable to avoid creating custom layout that could be used as a container for buttons.

  • 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-07T08:44:44+00:00Added an answer on June 7, 2026 at 8:44 am

    if i call getWidth derectly after inflatation it’s always return 0.
    To prevent it before get size i should init measure process by using measure function.
    This is my code (but i’ m not sure it’s the best and the fastest way)) ):

    ....
    view = inflator.inflate(R.layout.send_command_item, null);
    btnOff = (Button)view.findViewById(R.id.btnOff);
    btnOn = (Button)view.findViewById(R.id.btnOn);
    set_w(btnOff, btnOn);
    .....
    
    public void set_w(Button btn1, Button btn2) {
        btn1.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        btn2.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        int w1 = btn1.getMeasuredWidth();
        int w2 = btn2.getMeasuredWidth();
        if (w1 < w2)
            btn1.setWidth(w2);
        else
            btn2.setWidth(w1);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two buttons with the same ID: <button type=submit onclick=//do something id=theID>button 1</button>
I generated two buttons and put them into a list of buttons.. List<Button> buttons
I have two buttons in my layout say b1 and b2. By pressing b1
I have two buttons in my xml layout as shown bellow. I used an
I'm trying to put two buttons inside a panel using Swing widgets. Inside the
I have two buttons and two divs(I put one above another). I made info
I have two buttons in a horizontal field manager. one i want to put
I have two buttons that moves a movieclip up/down the Y-axis. How do I
I have two buttons, one for start recording and another for stop recording. i
I have two buttons, which the user can click and will open a FileDiagloag

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.