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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:56:30+00:00 2026-05-23T20:56:30+00:00

In the image below, the yellow square represents a RelativeLayout that’s within my overall

  • 0

In the image below, the yellow square represents a RelativeLayout that’s within my overall layout.

The top row “status message” is a ViewFlipper that responds to the ToggleButtons (A, B) that the user can press. Buttons C, D, and E do other stuff that reload the entire view. Our client is requesting that buttons A, B, C, D, and E be arranged as in the fashion below. (Vertical alignment isn’t as important as horizontal alignment.)

EDIT to say A, B, C, D, and E are images about 20×20 dip; they are being aligned within a width of about 300dip. I want the buttons to maintain their aspect ratio.

looking to make this layout

I’ve created an extension of LinearLayout that inflates buttons A and B (from an xml file), and then another LinearLayout that inflates buttons C, D, and E in another xml file.

Buttons A and B (are actually ToggleButtons):

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:baselineAligned="true"
>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
    >
        <ToggleButton
            android:id="@+id/A"
            android:textOn=""
            android:textOff=""
            android:background="@layout/A"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="60dp"
            android:layout_marginRight="30dp"
        />
        <ToggleButton
            android:id="@+id/B"
            android:textOn=""
            android:textOff=""
            android:background="@layout/B"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp"
        />
    </LinearLayout>
</RelativeLayout>

Buttons C,D,E xml file:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:baselineAligned="true"
>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
    >
        <ImageView 
            android:id="@+id/C"
            android:src="@drawable/C"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp"
        />
        <ImageView 
            android:id="@+id/D"
            android:src="@drawable/D"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp"
        />
        <ImageView 
            android:id="@+id/E"
            android:src="@drawable/E"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp"
        />
    </LinearLayout>
</RelativeLayout>

My code basically works, but I have to fudge with the margins to make things line up correctly (which they don’t yet). I wonder if there’s some cleaner way of center aligning button-sets “A B” and “C D E”

ps: the astute reader will notice that I’m extending LinearLayout, but inflating RelativeLayouts. (I don’t know why it can even work at all, but) when I tried extending RelativeLayout instead, the “C D E” layout didn’t even appear on my device. I don’t know where it went.

  • 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-23T20:56:30+00:00Added an answer on May 23, 2026 at 8:56 pm

    Use a linear layout as the main body.

    Then use layout_gravity on the individual horizontal linearlayouts to keep the content centred

    Use the layout_margin on each of the child view to space them apart. I have specified this as 15dip but you should use a dimension so you can modify them all together.

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <TextView android:id="@+id/some_text"
            android:layout_height="wrap_content"
            android:text="Some random string." android:layout_gravity="center" android:layout_width="wrap_content"/>
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center">
            <ToggleButton
                android:id="@+id/A"
                android:textOn=""
                android:textOff=""
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@layout/A"
                android:layout_margin="15dip"/>
            <ToggleButton
                android:id="@+id/B"
                android:textOn=""
                android:textOff=""
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@layout/B"
                android:layout_margin="15dip"/>
        </LinearLayout>
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center">
            <ImageView 
                android:id="@+id/C"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/C"
                android:layout_margin="15dip"/>
            <ImageView 
                android:id="@+id/D"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/D"
                android:layout_margin="15dip"/>
            <ImageView 
                android:id="@+id/E"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/E"
                android:layout_margin="15dip"/>
        </LinearLayout>
    
    </LinearLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The image below represents a website layout I am trying to create. The blue
I receive this message (see image below) when I try to edit in debugging.
I have an interface that has large numbers of controls, see image below. Interface
Looking at the image below, you can see that there are lots of javascript
The image below represents the footer The black arrow represents the expandable content Div
From the image below. It can be seen that I have three table User,
In the image below the button is being pressed. The shadow is square. How
The image below shows a input component from Facebook that helps in building a
I'm trying to position an image below a TextView in a RelativeLayout but it
I defined two CSS classes that set the background to an image (shown below).

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.