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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:35:36+00:00 2026-05-17T02:35:36+00:00

I have 4 buttons in a horizontal linear layout. I’d like the right edge

  • 0

I have 4 buttons in a horizontal linear layout. I’d like the right edge of the 4th button to align with the right edge of the linear layout (equal to screen width) I’ve tried using android:layout_gravity=”right” but it doesn’t work – the right button is to the right of the 3rd one but not right aligned . Am I missing something obvious?

main.xml with only the relevant layout params only is:

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
       <Button
           android:layout_height="fill_parent"
           android:layout_width="wrap_content">
       <Button SAME LAYOUT AS BUTTON 1>
       <Button SAME LAYOUT AS BUTTON 1>

       <Button
           android:layout_height="fill_parent"
           android:layout_width="wrap_content"
           android:layout_gravity="right" />
    </LinearLayout>
</LinearLayout>

This doesn’t seem to match the stated behaviour for layout_gravity in the SDK reference :”Defines how to place the view, both its x- and y-axis, within its parent view group.”

  • 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-17T02:35:36+00:00Added an answer on May 17, 2026 at 2:35 am

    I know this isn’t really the proper answer to your question, but you should really consider using RelativeLayout instead of LinearLayout. It scales better to different phone screen resolutions, and you can place the buttons in the correct order by using the layout_toRightOf and layout_alignParentRight attributes in your XML (or layout_above, layout_alignParentTop, etc.). Using gravity in a linear layout won’t really behave as you expect because Android is still attempting to place the widgets in a fixed position.

    RelativeLayout is a bit more of a pain to get working than LinearLayout, but it’s worth the trouble and is also the one which Google recommends using. Once you get the hang of it, they are very convenient to work with.

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

Sidebar

Related Questions

My coworker and I constantly argue about button sizes. I like to have buttons
I have 3 buttons in a form. One of them is the submit button.
I have a lot of buttons and by clicking on different button, different image
I have a page with some dynamically added buttons. If you click a button
I am using a linear layout to display a pretty light initial screen. It
I have a layout that is three linear layouts. The top has some icons
I have a snippet to create a 'Like' button for our news site: <iframe
I have added a LinearLayOut having some buttons My screen is RelativeLayOut it self
Is it possible to get the width of a linear/relative layout, if the layout_width
I have three buttons and need to save some data. I have a idea,

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.