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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:35:41+00:00 2026-05-25T15:35:41+00:00

I am trying to create my own buttons for a calculator application. My trouble

  • 0

I am trying to create my own buttons for a calculator application.

My trouble is that , i’m finding it hard to support all the different screen sizes.

Basically i have a number of buttons, created like this

<Button android:text="Button" android:id="@+id/button1"
    android:background="@drawable/test"
    android:layout_height="60dip" android:layout_width="60dip" android:layout_margin="5dip"></Button>

My background is an XML drawable

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Bottom 2dp Shadow -->
<item>
    <shape android:shape="rectangle">
        <gradient android:startColor="#E0E0E0" 
        android:endColor="#373737"
            android:angle="315" />
        <corners android:radius="20dip" />
    </shape>
</item>
<!-- White Top color -->
<item android:top="5dip" android:left="5dip" android:right="5dip"
    android:bottom="5dip">
    <shape android:shape="rectangle">
        <gradient android:startColor="#9E9E9E" android:endColor="#C5C5C5"
            android:angle="270" />
        <corners android:radius="20dip" />
    </shape>
</item>

Basically a background with rounded corners and what looks like a bevel , and a few gradients to make it look nice!

on 3.2 HVGA the buttons are the correct size

But when i view the buttons in 3.7 FWVGA , the aspect ratio is lost and there size is same size as 3.2 but as there are more pixels to work with on this screen the images are not the correct size.

Is there anyway to keep the consistency in this case???

  • 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-25T15:35:42+00:00Added an answer on May 25, 2026 at 3:35 pm

    The problem

    As you already mentioned, the issue is that there is more screen space available. This means you have to resize your buttons according to fill the available space, e.g. fill the available width of the display with 4 buttons, and scale their height so that the aspect ratio of the graphic stays intact.

    You are using dp units here, which is absolutely ok and good practice when defining layouts. But in this case it tells the layout “this thing has a fixed size of XX dp” (you can think of dp as a fixed unit, the fixed amount is just determined by the device that displays the layout). You don’t want a fixed size. You want the buttons to stretch in a dynamic way.

    A solution

    To provide a solution for your above layout: You can use a LinearLayout and it’s layout_weight attribute. Here is some short (incomplete) sample code to illustrate the principle:

    <LinearLayout android:orientation="horizontal"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content">
    
        <Button android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                />
        <Button android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                />
        <Button android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                />
        <Button android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                />
    
    </LinearLayout>
    

    What happens here?

    First we create an outer LinearLayout that fills the entire parent width (= the entire screen width) and adjusts it’s height depending on the content. Standard stuff.

    Then we add 4 buttons. The relevant piece here is layout_weight. This tells each button to “fill the available space as much as possible”. Since every single one tries to stretch out now, we have to define how much space each button gets. Thats the number given to layout_weight. Here we have the equal number one for each button. That means each button will be the same size as any other. So how does the layout determine how much space that is? It calculates the total weight of it’s children, which is 4 here and gives each children space according to the ratio child_weight/total_weight. So each button takes 1/4 of the width. (You can also assign any other number, if you give every button the weight 3, each button will get 3/12 of the width, which is still 1/4 according to math 🙂 )

    One question remains: Why layout_width="0dp"? That just prevents some unneccessary internal calculations inside as far as I know. All you have to know is use 0dp for the scaling dimension when using the layout_weight attribute. You can research a bit around if you want to know more.

    Samples

    Here are two screenshots of this in practice:

    2.7″ QVGA

    2.7" QVGA

    3.7″ FWVGA

    enter image description here

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

Sidebar

Related Questions

I am trying to create my own Native win32 C++ Checkbox that can have
I'm trying to create my own plugin. But I'm having trouble getting things right.
Trying to create my own Back/Forward buttons in xul. My Code: <label value= ❀
Im trying to create my own Frame for my application. I have removed the
I am trying to create my own lightbox for images on my website. Yes,
I'm trying to create my own Magento shipping module in Magento 1.6. Since I
I am trying to create my own torrent tracker but dont know how to
I'm trying to create my own templated List class as a practice excercise. I
I'm trying to create my own template for a List class as a learning
I am trying to create my own next and previous arrows in a fancybox

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.