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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:18:29+00:00 2026-06-14T08:18:29+00:00

I want to have a relative layout inside another full-screen relative layout, occupying full

  • 0

I want to have a relative layout inside another full-screen relative layout, occupying full width but 50% of its parent’s height, preferably done with XML and not java code.

I have figured out how how to align parent’s center, and how to fill up the width, but is there a way to get 50% of parent’s height? What about 30%? 6.2834%?

<?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">

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="??????????"
        android:layout_centerInParent="true" >

The reason I’m trying to do percentage is that, if I specify it with “dip”, while the object will remain the same size, the layout will look a lot different on different screen sizes (e.g. a phone and a tablet).

EDIT:

Thank you for all the answers about using LinearLayout and weighting. I have looked at that before, too. I feel I might have over-simplified the problem. Say I need something like this:

enter image description here

I suppose I could use complicated LinearLayout and weighting to outline the center square, then having the center square to fill_parent, like so:

enter image description here

But then what should I do with the other 3 squares (layouts)? Can I have another “layer” of LinearLayout for another square? Or should I divide up the whole screen into many, many small cells and having these sublayouts span over multiple cells (not sure if this is even possible)?

  • 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-14T08:18:31+00:00Added an answer on June 14, 2026 at 8:18 am

    I usually go with a LinearLayout for this and set the weight to a certain percentage :

    <?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">
    
        <View
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="25"/>
    
        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="50">
         </RelativeLayout>
    
         <View
             android:layout_width="fill_parent"
             android:layout_height="0dp"
             android:layout_weight="25"/>
    
    </LinearLayout>
    

    To your edit:

    At some point you need to determine the layout. Start by taking the layout in groups. Look for patterns. In your simple explanation we have devised a way using a linearlayout to group 3 objects with one in the middle. With your new layout, could you group those items in any way?

    Once you have simple layout patterns set, maybe add specific spacing that you are looking for by defining weights. Then you might want to add a relative layout and start anchoring views to specific views. Ask yourself do they overlap? Does one view always position on top of other views or on the sides. What defines the bounds of your views and then take it from there using linear layouts, weights, relative layouts, toLeftOf, toRightOf, bellow, above, margins, and padding.

    Here is an example of what I mean by grouping like objects. It’s by no means the best solutions but that all depends on how you define the positioning parameters.

    Yellow = vertical linear layout

    Green = horizontal linear layouts

    You have 1 large vertical layout and inside two horizontal layouts with multiple objects inside of that. From there you can break it down into easier to manage portions on how to arrange and item within that layout. Now with relative layouts you could position items relative to another object, you could remove some of the work handled by the linear layouts but you will then be defining their distance relative to the other objects and might have to fiddle to get the layout to adjust properly on different screen sizes (reason to not use static positioning).

    layouts

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

Sidebar

Related Questions

I want to center a text inside a TextView relative to the parent layout
I have an ImageButton that I want to fill its parent RelativeLayout container for
I want to position four div s relative to another. I have a rectangle
parent as relative layout i have textview (for title) and linearlayout for viewgroup in
I'm using a Relative layout as the root or parent container and I have
I have the following inside a relative layout. <TextEdit android:layout_width=wrap_content android:layout_height=wrap_content android:layout_alignBottom=@id/buttonA android:layout_alignParentLeft=true android:layout_alignParentTop=true
I have a relative layout within another layout that represents a menu bar on
I put 4 buttons in a relative layout. I want them to have the
I have this problem accessing TextView inside Relative Layout inside LinearLayout Let's say I
I have a simple HTML layout: <div style=position:relative; width:200px> <div style=position:absolute; top:0; left:0; background-color:red;

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.