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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:12:32+00:00 2026-05-22T16:12:32+00:00

I have a LinearLayout that has four views layed out horizontally. The first and

  • 0

I have a LinearLayout that has four views layed out horizontally. The first and last component are a set size. For the inner two views I want to just share the available space 50:50. I set each to a weight of “1” but when the views are layed out, the views are different sizes depending on the content they hold.
Screen shot of the layout. The data is hidden but it shows how offset the views are

Here is my layout xml for reference.

<?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">
    <ImageView 
        android:id="@+id/status" 
        android:src="@drawable/white"
        android:paddingRight="10dip" 
        android:layout_height="35dip" 
        android:layout_width="35dip">
    </ImageView>
    <TextView android:id="@+id/name" 
        android:text="Name" 
        android:layout_height="fill_parent" 
        android:layout_toRightOf="@id/status" 
        android:layout_width="wrap_content" 
        android:layout_weight="1" 
        android:textSize="25dip">
    </TextView>
    <TextView android:id="@+id/description"
        android:text="Description"
        android:layout_toRightOf="@id/name" 
        android:layout_height="fill_parent"
        android:layout_width="wrap_content"
        android:layout_weight="1"
        android:textSize="25dip">
    </TextView>
    <TextView android:id="@+id/time" 
        android:text="Time" 
        android:layout_width="wrap_content" 
        android:layout_height="fill_parent"
        android:layout_toRightOf="@id/description" 
        android:textSize="25dip">
    </TextView>
</LinearLayout>

Obviously these aren’t the actual column names but I changed them for privacy purposes. This layout is used by a ListView which changes the text of each view to be whatever value its presented. The name and description fields should line up since they’re both given 50% of the remaining screen but when the name is longer the description is shifted right. Why?

  • 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-22T16:12:33+00:00Added an answer on May 22, 2026 at 4:12 pm

    For the weight to be considered, the layout dimension needs to be 0 (zero)

    <TextView android:id="@+id/name" 
        android:text="Name" 
        android:layout_height="fill_parent"  
        android:layout_width="0dip" 
        android:layout_weight="1" 
        android:textSize="25dip">
    </TextView>
    

    I also recommend making your weight add up to either 1 (and use fractions) or 100.

    So instead of 1 you would use either 50 or .5 for each view. The LinearLayout code will work properly with any weight sum, but it gets difficult if you want to modify your view later with additional sections.

    Also, if you are not using relative layout, get rid of the toRightOf attributes. Less is more.

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

Sidebar

Related Questions

I have a View that inherits from LinearLayout that inflates itself. After it has
I need to have a layout that has a view above a set of
I have an extended BaseAdapter that has LinearLayout children (an ImageView and a TextView
I have a vertically oriented LinearLayout that has a child LinearLayout that includes a
This makes no sense. I have some code that has a simple LinearLayout and
I have the linearlayout which has the background set as rect.xml as mentioned below.
I have a LinearLayout that has 3 layouts at the top. (So the grey
I have a LinearLayout which has a background image (a 9 patched png file).
I have a Tab that has a custom layout which contains a TextView .
I have a fragment which has its own state (selected buttons, etc). That state

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.