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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:55:27+00:00 2026-06-16T04:55:27+00:00

Possible Duplicate: Android – gravity and layout_gravity I have been working on android xml’s.

  • 0

Possible Duplicate:
Android – gravity and layout_gravity

I have been working on android xml’s. I have used android:layout_gravity="center" to align components in specific position.

Now a days, when I was working on a Dialog like Activity, I came across android:gravity="center". What I found there was, gravity was used to align its child to a specific position.

I would share an example of what it is,

android:gravity=”center”

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical"
    android:orientation="vertical" >
            <EditText
                android:id="@+id/enterNumberEdit"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:hint="Enter No." >

                <requestFocus />
            </EditText>
            </LinearLayout>

It aligns the child of LinearLayout in center.

android:layout_gravity=”center”

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:orientation="vertical"
    android:background="@drawable/dialog_background" >
</LinearLayout>

It aligns the LinearLayout itself in center.

Now my questions are:

  1. If I am right in these assumptions, that whether gravity is for child components and layout_gravity is for parent component.
  2. When to choose gravity over layout_gravity.

I have found this much explanation working on xml’s so far. I would like to hear much better explanation of it. Let me know, if I am wrong somewhere

  • 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-16T04:55:29+00:00Added an answer on June 16, 2026 at 4:55 am
    1. Yes, your understanding is correct. Any layout_ attribute gives instructions to the parent view.
    2. Generally, if a view is taking up the full width/height of its’ parent, then you won’t need to specify layout_gravity, you’ll probably find gravity more useful. If your view does not take up an entire dimension of its’ parent, you might want to align it depending on your desired look.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Android Unknown Command 'crunch' I have been using eclipse just fine but
Possible Duplicate: Android XML Percent Symbol hi mate i have an array in file
Possible Duplicate: Android Button: set onClick background image change with XML? I need that
Possible Duplicate: Android: Set interval in SeekBar I have a seekbar with max value
Possible Duplicate: Android HttpClient : NetworkOnMainThreadException I am working on an application that is
Possible Duplicate: accelerometer in Android emulator I have an application that plays music when
Possible Duplicate: @Override annotation error (android prefs) I have imported a project into my
Possible Duplicate: Android: ProgressDialog.show() crashes with getApplicationContext I want to have a progress dialog
Possible Duplicate: Android : Location.distanceTo not working correctly? I am trying to calculate the
Possible Duplicate: Android dynamic String Resources I have the following: TextView text = (TextView)vi.findViewById(R.id.text);

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.