System indicators do not respect Gravity.BOTTOM - android

I have taken the demo analog watch face, and tried getting the system indicators to appear at the bottom, using setStatusBarGravity(Gravity.BOTTOM). It appears that this particular gravity isn't respected.
setWatchFaceStyle(new WatchFaceStyle.Builder(AnalogWatchFace.this)
.setCardPeekMode(WatchFaceStyle.PEEK_MODE_SHORT)
.setBackgroundVisibility(WatchFaceStyle.BACKGROUND_VISIBILITY_INTERRUPTIVE)
.setShowSystemUiTime(false)
.setStatusBarGravity(Gravity.BOTTOM)
.setHotwordIndicatorGravity(Gravity.BOTTOM)
.build());
By setting it to this value, the indicators (and the "Ok Google" hotword indicator) appear in the center of the screen. On circular devices, they appear completely centered, on square devices vertically centered on the left.
I'm aware of an issue on Android Wear that the indicators aren't updated between relaunches of the app, but I've tried switching watch faces and even reinstalling it altogether. I've also tried using setStatusBarGravity() combining with a horizontal alignment with a binary OR, but only the horizontal gravity is respected for square devices.
Any idea what the problem might be?

It seems that Gravity.BOTTOM is a bit misleading; the vertical alignment is not at the bottom of the screen, but in the bottom-most of some preset positions.
The position of the indicators appears to be relative; above any possible peeking cards and above the hotword indicator, if it is also set to Gravity.BOTTOM.
I found that if I set setHotwordIndicatorGravity(Gravity.CENTER), the system indicators appear slightly lower than setting both indicators to Gravity.BOTTOM. It's not ideal, but it's the best I could get. This no longer appears to be the case in Wear OS.
I've calculated the positions against a 390px circular display as:
Gravity.TOP: 8.7%
Gravity.CENTER_VERTICAL: 39.0%
Gravity.BOTTOM: 57.4%

Related

Position of Android controls ("home", "back", etc.)

For more pleasant UI, I'm trying to horizontally align few UI components of my activity with those controls of Android OS, which are always visible at the bottom of the screen: such as "back", "home", etc.
I thought, that Android OS controls are always distributed evenly across the horizontal axis. However, for some devices this is not true. E.g. on my Android Galaxy phone these controls are offset by few pixels, probably because of curved screen edges (just a guess).
I was searching for some generic Android API, which would give me access to these controls, but with no luck.
So my question would be: is there a robust way to horizontally align widgets of my Activity with Android OS controls visible at the bottom of the screen?
which are always visible at the bottom of the screen: such as "back", "home", etc.
They are not always visible on the bottom of the screen. That link refers to the four-year-old official Android support for gesture navigation; various manufacturers offered gesture navigation prior to that.
I thought, that Android OS controls are always distributed evenly across the horizontal axis. However, for some devices this is not true.
Device manufacturers can do whatever they want.
is there a robust way to horizontally align widgets of my Activity with Android OS controls visible at the bottom of the screen?
No.

Layout cropped on edge curved screen devices

I have a problem with layout being cropped when displaying on screens with curved edges. I have a simple layout with some edittexts and a button. The edittexts are cut off on the left side and it only happens on Samsung Edge devices. Can someone know how to deal with these curved edges screen, because adding larger margins seems like a workaround and on flat screens wouldn't look well .Couldn't find anything useful about the issue,.
Thanks in advance.
I believe there are 2 possible solutions to your problem.
WindowInsets: They describe a set of insets for window content. They make it easier to display your UI while taking in to account the system UI and factors of your display.
Guideline: If you are using a ConstraintLayout as your base layout, using guidelines as your horizontal bounds make it easier to design a responsive UI. For example you could set a horizontal guideline at 0.05 percent and another at 0.95 percent, which would keep you content away from the edges, while also keeping your UI responsive at various screen sizes and densities.

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: MarginLayoutParams not working well on all phones

I have a fullscreen view which I partially move in and out from the phone screen, let's say to the half of the screen.
To do this I am using MarginLayoutParameters to set the top margin to half of the screen, or to 0 in case I want it to be fully visible.
Everything works perfect but now that I am testing on other phones, which seem to be the ones of low resolution, the view is correctly cut by half but is always aligned to the top.
Trying left and right margins also always aligns it to the left.
Am I missing something that newer phones/ Android OS already does for me?.
This view is inside a FrameLayout.
Thanks in advance.
Well I just used setPadding with the same results I wanted to achieve, but my question still remains.

Dialog content not centered horizontally on Droid X

I'm creating a Dialog, setting a content view with two Buttons, and displaying it. Oddly enough, even though I properly centered it vertically and horizontally, on the Droid X extra blank space appears at the top and on the right side.
I discovered the top is reserved for the Dialog title; even when that title is blank, the space is kept empty. The workaround there is easy enough--I set a title.
The right side, however, baffles me. When I test the same app on other devices it works beautifully; the Droid X, however, keeps the right side of the screen empty. When the root layout of my Dialog's layout has a width of match_parent or fill_parent, it does not extend to that empty area. However, if I manually set a fixed large width, it does extend as far as it needs to--no more empty space on the right side. That's hardly an ideal solution though.
Does anyone know how to get around this Droid X layout quirk so Dialogs do not have that empty space on the right side?
After some experimenting, I found that if I change the margin and/or padding sizes, suddenly the Dialog becomes centered! For example: margins of 4dp creates an offset. But making the top, bottom, left, and right margins all larger and different makes the problem go away.
This sort of behavior generally means one of two things: There's a bug in how the layout is drawn, or I have a gross misunderstanding of how these things work. Both seem equally likely.
So my answer is: play with the margin (and padding) numbers. It's possible that you can find something that both works and is aesthetically pleasing.
Sorry, I know this answer sucks. So it goes.

Categories

Resources