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

  • Home
  • SEARCH
  • 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 7669415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:35:22+00:00 2026-05-31T15:35:22+00:00

I am trying to get 3 buttons aligned (left, center, right). I know that

  • 0

I am trying to get 3 buttons aligned (left, center, right). I know that it can probably be done with gravity but I wam trying to understand the layout_weight concept here. I am using this code:

<LinearLayout
id=..
layout_width =  "wrap_content"
layout_height = "wrap_content"
orientation="Horizonta"
>
 <Button
  id=1
  layout_width =  "wrap_content"
  layout_height = "wrap_content"
  layout_weight = "1"
  text= "text" />

 <Button
  id=2
  layout_width =  "wrap_content"
  layout_height = "wrap_content"
  layout_weight = "1"
  text= "text" />

 <Button
  id=3
  layout_width =  "wrap_content"
  layout_height = "wrap_content"
  layout_weight = "1"
  text= "text" />
</LinearLayout>

However, I am getting the TOP portion of the image below. Which is correct. The question is why is button stretched to cover all the area it is allocated while I am using wrap_content?How can make it like the BOTTOM image?

enter image description here

Thank you

  • 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-05-31T15:35:23+00:00Added an answer on May 31, 2026 at 3:35 pm

    The layout_weight is used to indicate how the extra free space on the screen should be divided up among the widgets. In this case we have three buttons with the same layout_weight and hence so will the buttons grow equally much until all the free space is gone.

    Must try something else to get original size buttons and the alignment that what we want (left – center – right). One problem is that the horizontal LinearLayout is not completely collaborative when it comes to respecting layout_gravity parameters. We will be able to use layout_gravity parameters that affect vertical alignment but horizontal are ignored by the parent LinearLayout, sigh another dead end.

    A solution is to put something in between the button’s that pushes the them into right place in the screen. The Space view was introduced in API 14 (Ice Cream Sandwich) and is suitable to be used for this.

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
    
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
    
         <Space
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight = "1" />
    
        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
    
        <Space
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight = "1" />
    
        <Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
    
    </LinearLayout>
    

    The Space views can also be replaced with a couple of empty TextViews to get the design to work on devices that run earlier API-levels.

    <TextView
        android:id="@+id/textView1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1.0"
        android:text="" />     
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 3 buttons. I'm trying to get it so that when one is
I have been trying to get simple YES/NO radio buttons list working but facing
I am trying to get two android buttons to appear inbetween two textviews. But
Trying to get an ASP application deployed; it worked for a while but then
I am trying to get 2 buttons to be beside each other and evenly
I'm trying to get the id of the set of radio buttons. Here is
I'm trying to get two buttons to show up next to each other in
I am trying to get away from using 5 buttons when I would like
I'm trying get all the button child widgets of a window. The buttons were
I am trying to make 3 rows of 4 buttons each that will take

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.