How to handle accessibility zoom / font size changes? - android

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

Related

Android: Scale a view like image?

I was creating a banner layout for our App and it turns out that there are essentially two options I have:
Have a static image for the banner
Create a banner layout that actually lays out individual elements of the banner image. This option enables changing the banner content at runtime.
Initially, I thought that creating a dynamic banner(option 2) should always be the way to go(unless you have time crunch) but it turns out if the layout is to be changed in width and height, the margins, dimensioning and position of the views might change. As an example, if there is a TextView that is supposed to take up only single line might spill over to second line if the width is shrunk. This is the case with the dynamic layout.
With static layout, overall image would scale down therefore, although the font size would go down a bit, the text would remain in one line only.
Now, this seems to be the obvious disadvantage with dynamic layouts, is there any way I can fix it...like maybe scaling up/down a view like an image instead dynamically adjusting the positioning and whatnot for the views involved?
Or, having a static banner design is preferred?

How to make a textView stick to the same position on imageView background with different screen ratios

-I'm new to constraintlayout and I want to constraint a textview in some specific places on imageView like in here
-I tried to use guidelines anchoring the text to them like this but it didn't show the same between different screen sizes
so I need a way to connect the text to the image in way the text be all the time in the place I needed to be in different ratios
My suggestion would be to anchor each of your views to the top and bottom of the page and then set the slider % to 25% and 75%. You can adjust the views that way so that they're always relatively similar in positioning no matter the screen size.

android layout - position ImageButtons in equal quadrants of the screen and size them to proportion

I am creating an android app and I am having some trouble with the XML file. What I want is four ImageButtons displayed in the center of four quadrants of the layout (so one in each quadrant). I also want thees ImageButtons to be sized by a percent of the screen (so the button would be bigger on a bigger screen and smaller on a smaller screen) but to a maximum of a specific size.
description of what I have in the layout that works:
The layout that contains thees buttons takes up 70% of the screen height and maximum width (there is another layout in the top 30%) and the screen is locked in vertical orientation. so I'm only looking to complete this quadrant ImageButton style of view.
my attempts to accomplish this was:
1) grid layout: this wrapped my buttons up and they did not take up the whole screen or one quadrant filled up the whole screen and the other three quadrants were not visible.
2) layout dimension percent: several linear layouts positioned in vertical and horizontal orientation and using the layout_hight=0dp (or width), layout_weight="0.50" "trick" to position the quadrants out. This worked nicely but there is a warning i get that the layouts are inefficient when you use a percentage to size a layout within a layout that was position with a percentage, and the ImageButtons did not want to stop at a maximum size completely ignored maxHight & maxWidth (i did have adjustViewBounds="true").
3) I can make all this work easily by calculating sizes and positioning everything by code but I would really like to do this in the xml file and leave that as a last resort.
I would appreciate any help, even a push in the right direction would be grate. I have been stuck on this for a while thank you.
Just do it programatically. It's much simpler as xml is very static and java is dynamic and in complex situations easier to use. Save yourself the trouble.

Arranging Components in App Inventor?

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.

Draw Custom View on specific position of screen - Android

I have a custom component which consists of 2 text view and 4 toggle buttons. I want to draw this view at some specific position on the screen. How is that possible?
You could wrap the controls in a Layout, e.g. a LinearLayout, and add android:paddingLeft and android:paddingTop by some pixel value to that Layout to position it how you want.
However I would advise that Android Layouts are better designed with relative positions rather than absolute positions. Different devices have different screen sizes, and unless you prohibit it your layouts can be switched between Portrait to Landscape ratios without warning. Layouts designed with relative positioning hold up much better under these conditions. The RelativeLayout container allows tricks like centering controls on the screen, and aligning them relative to other controls.
http://developer.android.com/intl/de/reference/android/widget/RelativeLayout.html

Categories

Resources