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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:14:49+00:00 2026-06-13T19:14:49+00:00

I’m making a layout (XML file) in Android that has two child views (one

  • 0

I’m making a layout (XML file) in Android that has two child views (one on the right side of the screen and one on the left). I want the view on the right to take up a pre-determined space (in dp) and have the view on the left take up all the remaining space up to a limit, at which point it will stop expanding and the two layouts will just move further apart as the screen gets larger.

The odd thing is this would be very easy if I wanted the view on the right side to be the one that expands, and the view on the left to be the one that takes up a preset space. If you set each view to the width you want (in a horizontal linear layout) Android will automatically shrink the one on the left in the event that both views don’t fit.

I would like to do this in one layout file; this layout is already designed for displays between sw512dp-land and sw765dp-land.

The code below would work if I could find a way to make Android shrink the layout on the left (when layouts both cannot fit at the size specified). But by default the system will shrink the layout on the right first.

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >

<RelativeLayout
    android:id="@+id/left"
    android:layout_width="150dip"
    android:layout_height="fill_parent"
    android:background="@color/red" >
</RelativeLayout>

<LinearLayout
    android:id="@+id/right"
    android:layout_width="100dip"
    android:layout_height="fill_parent"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:background="@color/green" >
</LinearLayout>

This code (from @Lokesh) would work if I didn’t need the layout on the left to stop expanding at a certain point.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >

<LinearLayout
    android:id="@+id/left"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_toLeftOf="@+id/right"
    android:background="@color/red" >

</LinearLayout>

<LinearLayout
    android:id="@+id/right"
    android:layout_width="100dip"
    android:layout_height="fill_parent"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:background="@color/green" >
</LinearLayout>

It would also be nice to know if anyone thinks this isn’t possible so I can resort to doing it pragmatically or changing my approach to the layout.

Thanks!

  • 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-13T19:14:50+00:00Added an answer on June 13, 2026 at 7:14 pm

    This works for me. I’ve set the right layout to 100dip, change as per your needs.

    <?xml version="1.0" encoding="utf-8" ?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal" >
    
        <LinearLayout
            android:id="@+id/left"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_toLeftOf="@+id/right"
            android:background="@color/red" >
    
        </LinearLayout>
    
        <LinearLayout
            android:id="@+id/right"
            android:layout_width="100dip"
            android:layout_height="fill_parent"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:background="@color/green" >
        </LinearLayout>
    
    </RelativeLayout>
    

    EDIT 1: I used the background color just to distinctly show the layouts. Not necessary at all. 🙂

    EDIT 2: If you want a way to expand the left layout upto only a limit then try this –

    <?xml version="1.0" encoding="utf-8" ?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal" >
    
        <LinearLayout
            android:id="@+id/left"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_toLeftOf="@+id/right">
            <LinearLayout 
                                android:id="@+id/inner"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"         
                android:background="@color/yellow">
    
                <TextView
                    android:id="@+id/myTextView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="This will expand only to a limit"
                    android:maxWidth="300dip"
                    android:textAppearance="?android:attr/textAppearanceLarge" 
                    android:background="@color/red" />
    
            </LinearLayout>
        </LinearLayout>
    
        <LinearLayout
            android:id="@+id/right"
            android:layout_width="100dip"
            android:layout_height="fill_parent"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:background="@color/green" >
        </LinearLayout>
    
    </RelativeLayout>
    

    Here you need to place your widgets in inner layout and this is what it looks like in different screens.

    3.1in HVGA
    3.2in HVGA

    5.2in QVGA
    5.2in QVGA

    Colors used : red(#FFFF00), yellow(#FFFFFF00), green(#FF00FF00).

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

Sidebar

Related Questions

In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm parsing an XML file, the creators of it stuck in a bunch social
I'm making a simple page using Google Maps API 3. My first. One marker
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.