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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:55:40+00:00 2026-05-29T18:55:40+00:00

I have spent hours trying to work this out, and spent a long time

  • 0

I have spent hours trying to work this out, and spent a long time looking through other answers.
I’m evidently missing something simple, but really have been trying.

I cut my code down to the very basics to find the problem.

A layout has a backround, the top half of which is nice graphics, below the top half I am hoping to have the buttons.
The background is on the top, first linearlayout ( vertical ).
Then, inside this, are two vertical linear layouts.

The top vertical layout, has a weight of 1.
The bottom vertical layout, has a weight of 1.

This means to me, that the top layout should take up HALF of the screen. The buttons then going in the second layout should be ok to take up the rest of the screen.
However, when I start adding to the second layout, it no longer takes up half of the screen, but starts taking up space on the top half.

All I want to do, is to add four imagebuttons to the bottom half of the screen, centralised horizontally.

here is my code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@drawable/menubackground"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <!--  Layout 1, the top half -->
    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical" >
    </LinearLayout>

    <!-- Layout 2, the bottom half, containing buttons -->
    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical" >

        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:src="@drawable/playbtnimg" android:layout_weight="1"/>

        <ImageButton
            android:id="@+id/imageButton2"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:src="@drawable/achievementsbtnimg" android:layout_weight="1"/>
    </LinearLayout>

</LinearLayout>

Those two buttons, are now starting to take up around 2/3rd of the vertical space. They should not be going into the top half of the screen.
I’m trying to use layouts in this way so it will work on different screen sizes.
I would like the images to scale to fit within their linear layout cell, and not be cut off at the top of sides.

Any help is much appreciated.

  • 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-29T18:55:42+00:00Added an answer on May 29, 2026 at 6:55 pm

    Add a weightsum attribute to your root element ie the parent LinearLayout

    here is what it would look like

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@drawable/menubackground"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:weightSum="2"
    android:orientation="vertical">
    

    same would be for the LinearLayout having buttons

    This would help further you can read more in android documentation

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

Sidebar

Related Questions

I have spent many hours trying to work this damn thing out! so I
I have spent the last several hours trying to get this to work and
I've spent many hours trying to get this to work. And I'm getting quite
I have spend about 3 hours trying to figure this out and it seems
I have spent hours trying to find an answer to this, and have come
I have spent hours trying to understand why my logger class does not work.
I have a problem with php header redirect. I already spent hours trying to
I hope this is a relatively easy problem although I have spent hours websearching
I have a really frustrating error that I've spent hours looking at and cannot
To begin, Ive spent several hours looking for an answer and have come CLOSE

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.