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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:10:44+00:00 2026-06-11T06:10:44+00:00

I have a LinearLayout that comprises some number of TextViews. I set android:gravity=center_horizontal for

  • 0

I have a LinearLayout that comprises some number of TextViews. I set

android:gravity="center_horizontal"

for the parent Layout and result looks as below (for N=2):

enter image description here

I want it look like

enter image description here

In other words, I want them to be aligned to the left. More precisely, my plan is to find the longest TextView and then align other TextViews to the left bound of that view. Can anyone explain me in what callback of my Activity can I do it? I tried

public void onCreate(Bundle savedInstanceState)

but

textView.getWidth()

(that I use to find the longest TextView) returns 0 for all textViews.
The second question is: what method should I use to move a TextView “n” pixels left?

  • 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-11T06:10:45+00:00Added an answer on June 11, 2026 at 6:10 am

    Hmm, it looks like the easiest route to get to what you want is embedding the LinearLayout in another Layout instead of attempting to do it by hand.

    Possible approach:

    RelativeLayout with gravity:center
      Linear Layout with gravity:left and wrap_content as size
        TextView1, wrap_content
        TextView2 
        ...
    

    This should do the trick!

    BTW, if you try to do anything with layout, overriding onCreate will never work! The layout will only be defined afterwards, when the drawing framework completed one “onMeasure” and one “onLayout” cycle. A (hacky) way to ensure that, is simply postpone that code (e.g., use “View.postDelayed(..)”. A better way would be to have a custom, invisible View that is added in the onCreate method. When its onDraw was called for the first time, you can be sure that at least the first layout cycle was completed. All Views should then return their actual size.

    In terms of moving Views: Did you have a look at “View.setOffset”?

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

Sidebar

Related Questions

I have this simple layout: <?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=fill_parent android:orientation=vertical >
I have an ImageView that I set to center inside the LinearLayout of a
I have a LinearLayout that I use as a container for some buttons and
I have a horizontal LinearLayout, inside which I have 2 TextViews. Let's say that
I have a layout that I am using as a parent layout template. Depending
I have a LinearLayout with a vertical orientation, within that layout I have three
I have a LinearLayout layout with a ListView in it. I've made the android:background
I have a code that should get a LinearLayout (with more LinearLayout's inside), and
There is one image on LinearLayout. I have to move that image in any
I have a Linear Layout that has a Button and a TextView on it.

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.