Arranging Components in App Inventor? - android

Is there a more precise way of arranging components in App Inventor than using the Vertical/Horizontal/Table Arrangement formatting elements?
I want to sparsely position about six buttons across my app screen - all different sizes.
Thank you in advance.

the short answer is: no
well, additionally you also could use empty labels as delimiter between components...
another answer is: you could use a canvas and sprite components instead of buttons. You can define sprite positions exactly at x/y coordinates of your canvas.
However keep in mind, that there are different Android devices with different screens sizes and resolutions, so normally you wouldn't set buttons exactly at x/y coordinates to avoid strange layouts for e.g. smaller or larger devices.

The bit longer answer is to use labels as spacers.
Example:
Need to center a button at the top of the screen.
Add horizontal layout with 2 label texts and button in center inside of the layout.
Click each text label and remove the actual text from right side properties menu and choose fill parent width and height.
This centers the button because the layout automatically assigns one third size to each.
Labels are the best, but longer coding answer.

Related

How to handle accessibility zoom / font size changes?

When I modify accessibility settings zoom and font size in Android my app layout is all broken.
I'can't find information about good practice to avoid this.
Most of my screen are not lists and are not scrollable, I have a bottom area with button, and in the middle I have complete layout with text fields / buttons / input / ...
Font size is too big so the text gets clipped vertically and horizontally.
Buttons don't fit in the width and display one over the other.
Do I have to manage this with different layouts depending on screen size?
Is there a way to automatically truncate text with "..."?
Is there a way to prevent some part of my layout to zoom (ex navigation part / lower button area)?
How do I prevent view from displaying one over the other (I use contraint layout)?
If I had to take a guess though, you probably are using a constraint or relative layout and haven't made the appropriate adjustments for all the child objects.
For truncating, try looking here - Android: TextView automatically truncate and replace last 3 char of String
For font sizes, it's recommended to use "sp" for the unit type, e.g. "15sp".
For constraint layouts, you need to set the anchors for each child object or they end up bunching up in the middle together.
this is a tutorial on constraint layouts - https://codelabs.developers.google.com/codelabs/constraint-layout/index.html?index=..%2F..%2Fio2018#0

Controlling the positions of a views in Android

I am trying to create an android app where I have a single relatively big button in the middle (the light blue in the picture) and it is surrounded by other smaller buttons as shown in the picture (some of small buttons might be visible or invisible based on some criteria).
I started with the RelativLayout setting the big on in the center and making the rest placed in relation to it, but it is a miss and the central button get shifted and doesn't stay in the center. I tried placing them in FrameLayout and used margin to adjust their locations, that worked the best however, the spacing changes on different screen resolutions.
So what is the best way to achieve such layout that will look consistent on any device?
Android's Percent Support Library allows you to use proportions to lay out your views, which may allow you to get closer to your goal.
http://developer.android.com/tools/support-library/features.html#percent

Android: Selecting Layout/ How to format Design for Calculator

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:
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?
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!

Which layout to use and how to achieve the following?

I have been struggling to figure out which layout to use and how to achieve what I am looking for. I've tried gridlayouts, linear and relative layouts as well as scroll views in many different combinations. What I want is something like Google now.
I have two buttons to launch the two modes in my app. I have an imagebutton in the top right which they press for more information and when they do so a text view slides out. I have made the layout work, and to overlay the imagebutton on my mode buttons I require a relative layout. However my problem comes from trying to optimise for different screen sizes. I would like it to centre the buttons to rest a quarter of the way down and the layout to pop out underneath towards the half way mark. For the bottom button I want it three quarters of the way down with a text view that drops down towards the bottom. If there isn't sufficient space to fit everything I want a scroll view for when the text views appear, but otherwise it should fit comfortably and not require scrolling.
How do I do this? Two nested relative layouts within a linearlayout, both with equal weight? Then some how I need to address that if the length of the height (taking in account orientation) does not allow it to fit, adapt it so the buttons are closer and scrollable.
You can use sepperate res/layout folders for different screen sizes just like with drawables, examples: layout-small, layout-large etc.
More explained here http://developer.android.com/training/multiscreen/screensizes.html#TaskUseWrapMatchPar

Which layout is suitable for all Android mobile?

I am developing one application, right now i am on designing phase. i design one screen
on the 3.7WVGA(Nexus One) screen in eclipse using Linear Layout. but when i test it on 2.7
my some icon are go outside of the screen. my question is that which layout is suitable for all screen whether i design it in 3.7 inch or run it on 2.7.
Please give me a suggestion.
Thanks in Advance.
1st i design it in 3.7 and second in 2.7.
Don't ever, ever, ever design a screen for Android based on an actual screen size. You will always screw yourself up because there are a hundred different screens out there. What looks good on one phone will look like crap on another. That being said, here are some tips:
Use RelativeLayout to lay your button contents out. Once you understand the model it's much easier than you suspect and it will make it easy to automatically scale things.
Only use actual pixel sizes for things that "float". You never want to specify the width of something and try to fill the width of the screen.
Include multiple resolutions of your images. Let the system pick the right resolution for you.
A table/grid layout will make things easier for you on the overall design.
Big panels of buttons are played out. There are other UI options at your disposal (menu buttons, swiping left and right through screens, etc.). When users see a field of buttons it looks like the app was slapped together.
For that kind of layout use GridView if you want it scrollable, or a simple RelativeLayout if you want all the elements to scale depending on the size of the screen (use toRightOf, toLeftOf, above, below and weight to achieve that)
You need to consider the guide provided by android
Multiple Screen Support
What you will do is to provide all screens icon regarding different screens and you can also specify layouts for different screens, for example you want to provide drawables and layout for multiple screens, you will provide resources in that specific folder + below suffix.
Screens for layouts for drawables
ldpi layout-small drawable-ldpi
mdpi layout drawable-mdpi
hdpi layout-large drawable-hdpi
xhdpi layout-xlarge drawable-xhdpi
This topic will be more relavent to your need.
The following are the view groups in android. you can use any of these as per your requirement. But in your case You can use GridView
View Groups in android
FrameLayout Layout that acts as a view frame to display a single
object.
Gallery A horizontal scrolling display of images, from a bound
list.
GridView Displays a scrolling grid of m columns and n rows.
LinearLayout A layout that organizes its children into a single
horizontal or vertical row. It creates a scrollbar if the length of
the window exceeds the length of the screen.
ListView Displays a scrolling single column list.
RelativeLayout Enables you to specify the location of child objects
relative to each other (child A to the left of child B) or to the
parent (aligned to the top of the parent).
ScrollView A vertically scrolling column of elements.
Spinner Displays a single item at a time from a bound list, inside
a one-row textbox. Rather like a one-row listbox that can scroll either horizontally or vertically.
SurfaceView Provides direct access to a dedicated drawing surface.
It can hold child views layered on top of the surface, but is intended for applications that need to draw pixels, rather than using widgets.
TabHost Provides a tab selection list that monitors clicks and
enables theapplication to change the screen whenever a tab is clicked.
TableLayout A tabular layout with an arbitrary number of rows and
columns, each cell holding the widget of your choice. The rows
resize to fit the largest column. The cell borders are not visible.
ViewFlipper A list that displays one item at a time, inside a
one-row textbox. It can be set to swap items at timed intervals,
like a slide show.
ViewSwitcher Same as ViewFlipper.
I have the same problem but i found a very simple solution is use dp and sp instead px. You may read this:
What is the difference between "px", "dp", "dip" and "sp" on Android?
And you may create icons with different resolution and put it in suitble folder.
create a table layout and every row contains a vertical linear layout put all buttons inside and provides weight to each button according to need,at the last put this table layout to ScrollView that is suitable for all android devices
I created a tool that allows you to scale/adjust your layouts for tablets and small screen devices and made a blog post about it here: http://onemanmobile.blogspot.com/2012/04/how-to-scale-your-android-layouts-to.html
Basically, defining your layouts in dp units for one size is not enough if you want your app to fit on all devices and tablets, since there's four different "density-buckets". This tool will allow your layouts to be converted into fitting these density buckets.
It also explains in further detail how to make more flexible layouts for all resolutions.

Categories

Resources