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

The Archive Base Latest Questions

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

I have a layout in which I want two ToggleButton widgets centered horizontally; not

  • 0

I have a layout in which I want two ToggleButton widgets centered horizontally; not right next to each other, but as if each was centered in their own half of the view.
So, I'm wanting them to look like this.

But instead I get this.

Here is the code for my layout:

`<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
<LinearLayout android:id="@+id/pics"
        android:layout_weight="2"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:padding="8dp"
        android:layout_alignParentTop="true" >
    <ImageView android:id="@+id/prefix"
            android:layout_weight="1"
            android:layout_height="fill_parent"
            android:layout_width="wrap_content"
            android:padding="4dp"/>
    <ImageView android:id="@+id/suffix"
            android:layout_weight="1"
            android:layout_height="fill_parent"
            android:layout_width="wrap_content"
            android:padding="4dp" />
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        orientation="horizontal" >
    <LinearLayout android:layout_weight="1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            orientation="horizontal" >
        <ToggleButton android:id="@+id/lockPrefix"
                android:textOn="Locked"
                android:textOff="Unlocked"
                android:checked="false"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal" />
    </LinearLayout>
    <LinearLayout android:layout_weight="1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            orientation="horizontal" >
        <ToggleButton android:id="@+id/lockSuffix"
                android:textOn="Locked"
                android:textOff="Unlocked"
                android:checked="false"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" 
                android:layout_gravity="center_horizontal" />
    </LinearLayout>
</LinearLayout>
<LinearLayout android:id="@+id/toolbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_below="@id/pics"
        android:padding="8dp" >
    <Button android:id="@+id/mixButton"
            style="@style/DefaultButton"
            android:layout_height="wrap_content"
            android:layout_width="90dp"
            android:text="@string/main_mixButton"
            android:onClick="mixButtonClick" />
    <Button android:id="@+id/exitButton"
            style="@style/DefaultButton"
            android:layout_height="wrap_content"
            android:layout_width="90dp"
            android:text="@string/main_exitButton"
            android:onClick="exitButtonClick" />
</LinearLayout>
</LinearLayout>`

(EDIT: make XML readable)

  • 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-23T02:13:30+00:00Added an answer on May 23, 2026 at 2:13 am

    You need to place each button into a LinearLayout, set layout_width of these layouts to fill_parent, layout_weight to 1 and gravity to center_horizontal. Hope this helps!

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

Sidebar

Related Questions

I have a layout in which I am displaying a webview . I want
I have created a custom tab layout which look like this,I want to make
I have a gridview in which there are two elements in each of its
I have two widgets, one arbitrary (usually a QLineEdit), and one QLabel which displays
I have a two column layout in which I have a static width for
I have a FrameLayout in which I have placed two identical TextViews. I want
In My application XML layout, I have one Relativelayout, In which there are two
I want to have a list view with each row having two buttons like
I have two QDialogs stacked on top of each other, with some data is
I have a layout which uses min-width and works great. So I came to

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.