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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:53:40+00:00 2026-05-25T16:53:40+00:00

For many header TextViews across the pages I’m designing for a program, I would

  • 0

For many “header” TextViews across the pages I’m designing for a program, I would like them to be the parent.Width / 2 then properly aligned. While that would be fairly easy to code in the Java, I am attempting to do as much as possible in the XML layouts to avoid XML-Java code intersections until the last little bits (button presses, finish page, etc).

Do I have to go through each page and calculate every item’s specific width myself or is there a way to put something along the lines of “fill_parent / 2”?

EDIT: Forgot to mention what is likely a key note – almost everything I am doing is in RelativeLayouts, I have very little use for LinearLayouts in this project.

  • 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-25T16:53:40+00:00Added an answer on May 25, 2026 at 4:53 pm

    If you have a LinearLayout that is flush to the left and right, you can do the following:

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:weightSum="2"
        android:gravity="left"
        android:orientation="horizontal">
        <TextView
            android:layout_weight="1"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:text="I take up half the width!!!1" />
    </LinearLayout>
    

    By setting the weightSum on the parent, you’re saying that the weights of the children should equal that amount. By setting the single child’s weight to half of that, it’ll take up half the space. Make sure to set the width of the child to 0 so it knows to use the weight value to calculate its space relative to its parent.

    Then, you can align it however you’d like by setting gravity on the parent LinearLayout.

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

Sidebar

Related Questions

I have many sub pages, there urls like www.domain.com/sub/page1.php www.domain.com/sub/page2.php ... Now when I
I am developing a website that many pages share the same header/footer/sidebar/topbar. Say I
I have to include many header files, which are in different sub-directories. Is there
The company I work for has recently been hit with many header injection and
There're many ways to write an HTTP-status header: HTTP/1.1 404 Not Found Status: 404
I'm trying to create proper header files which don't include too many other files
I have seen below macro in many topmost header files: #define NULL 0 //
How many characters can the value of the X-Forwarded-For (XFF) HTTP header value be?
When I define a to many relationship between entities in Xcode and then generate
It's common to have many pages in a website that request the same model

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.