-2

I am wondering how I would design a calculator with graphics similar to the following: Design help for Calculator App or https://play.google.com/store/apps/details?id=jp.Appsys.PanecalST.

The key requirements:

  • The buttons must be squared (it can pop out etc. but squares are more aesthetically pleasing than rectangles).
  • It must be device compatible and retain square buttons upon orientation change

My problem is that Relative formatting (as I attempted) disorients the layout in different devices and is not as nice as I hoped. (i.e. trying to design the button to harbor no empty space in one device using relative instructions. One idea I fancy is putting a center button and orienting the others above left etc. so at the very least, no empty space is in the center.

Below is the designs I made:enter image description here

I prefer the first image but I neglected 0 (only buttons for 1-9). How would attempt at transforming these designs to code?

*I think I may use ImageButtons. I will include images based on density but how would I account for different screen sizes?

Community
  • 1
  • 1
Andy
  • 337
  • 5
  • 16

1 Answers1

1

First of all, for your calculator, use LinearLayout. Link: Documentation will be found here

Secondly, To Support multiple screen, This documentation will help, documentation1, documentation2

What would I do in this situation?

First of all, I would use the LinearLayout as my primary layout and give it an orientation > Vertical instead of RelativeLayout. This LinearLayout is for the whole screen (The output, the numbers and other functions). Then for each line, say for the output screen, I would put it in another LinearLayout (Orientation Horizontal) inside the previous LinearLayout (NestedLayout). For numbers in each row, I would use a new LinearLayout.

For the second problem of yours, I would use buttons instead of images as images take large space in perspective of buttons which will unnecessary increase the app size. To support my button for multiple screen, I would use Weight option in android for buttons. This stackoverflow answer has a nice description.

I hope it helps. Cheers mate!

Community
  • 1
  • 1
  • 1
    Wow that is a really nice idea, using weight! I will try to design it using your recommendations! Thanks so much for taking the time to give this advise! It probably improved my code by lots. – Andy Jun 27 '15 at 19:07
  • @Andy,Thanks and Good luck mate :) –  Jun 27 '15 at 22:46