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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:08:28+00:00 2026-05-21T22:08:28+00:00

Is it possible to set in the XML layout file the size of the

  • 0

Is it possible to set in the XML layout file the size of the button so that, on one hand, it doesn’t take the entire width of the parent (screen) and, on the other hand, doesn’t use absolute pixel values?

To better explain my question, the problem in the following snippet is that "match_parent" takes the entire width:

<Button android:id="@+id/btn_1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="16px"
    android:paddingLeft="16px"
    android:paddingRight="16px"
    android:paddingTop="16px"
    android:text="@string/first_button" />

I know that it’s possible to control the size during runtime but I am interested to know whether this is possible in an XML file as well.

Is there something like android:layout_width="match_HALF_parent"?

  • 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-21T22:08:29+00:00Added an answer on May 21, 2026 at 10:08 pm

    The raw example could be like this:

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    >
        <Button
            android:text="Button"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginBottom="100dp"
            android:layout_marginTop="100dp"
            android:layout_marginLeft="50dp"
            android:layout_marginRight="50dp"
        ></Button>
    </LinearLayout>
    

    Alternatively, you could set android:padding to your layout instead of margin to button.

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

Sidebar

Related Questions

It's possible to set a layout width in inches using the input.xml file: <LinearLayout
Possible Duplicate: Android Button: set onClick background image change with XML? I need that
In my layout.xml file, is it possible to set text with style? e.g. this
Is it possible to set env vars in pom.xml that junit tests uses? Netbeans
Is it possible to set welcome-file tag from standard web.xml file by servlet 3.0
Is it possible to generate a set of wiki pages from XML comment file
Possible Duplicate: XML Table layout? Two EQUAL-width rows filled with equally width buttons? I
Is it possible to set TimePicker hours mode to 24-hours-mode in XML file? Or
Is it possible to set up a cron job that will execute a php
Having trouble setting a block template in Magento's layout xml. I'm attempting to set

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.