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.
Related
I don't know if this is the right place to ask for a solution.
I have a weird bug on Samsung S9 Android 8.0:
The area for the 3 Buttons (Menu, Home, Back) is blocked for some apps, so their UI ends on the top border of this area although I set these buttons to not fixed so that I have to swipe up to see them. One of these apps is Instagram.
Also, there is the problem that the outline of some UI is shining through the current UI of each app, no matter which app is currently running. This UI is always the same. I removed all UI elements from an app I'm working on so that I have a completely white screen. Then I made a video because on screenshots the UI fragments are not visible:
https://der-magere-student.com/public/media/WIN_20210115_02_29_04_Pro.mp4
On the bottom you can see:
In more or less black: the android menu buttons (BUT NOT THE REAL ONES, the real ones are hidden until I swipe up)
In more or less white: 4 of the five toolbar button of Instagram (home (house icon), the magnifying glass, the Plus (inside the android home button), and the heart) The fifth is not visible
On the top you can see:
The right side of the WhatsApp toolbar: From right to left. The more icon, the call icon, and the video call icon
horizontally centered with a bit offset from the top display border you maybe can see a little bar. I don't know where this comes from
There is a lot more but it's not visible on the video and also not identifiable for me. But I can see something.
Does anyone know where this bug comes from? Is it known? How to fix it?
You're looking at OLED screen burn-in. It's not a software problem; it's actually wear on the screen that happens slowly over time.
The UI you're seeing at the bottom of the screen is Android's navigation buttons, which are particularly notorious for getting burned into the screen (see, for instance, this image from this article), because they're always in about the same spot. Newer versions of Android take measures to reduce the burn-in from them, but there's only so much that it's possible to do.
Try opening something that shows a white screen with the navigation buttons hidden: you'll see the same thing.
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
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%
I'm developing a simple app with a customized background and a button in the middle.
I've got the whole different resolutions for different screens down, but do all the versions of the background need to be 9patches? How do I take into consideration the always there android top navigation bar and the possible use of advertisements at the bottom? Do they just cover the design or do they change the resolution?
I've got the whole different resolutions for different screens down
that's not how it works on android. see this:
http://developer.android.com/guide/practices/screens_support.html
do all the versions of the background need to be 9patches?
no . you decide . normally, buttons and views use the 9 patch images, but it can be useful for many other things. more info:
http://android10.org/index.php/articlesother/279-draw-9-patch-tutorial
http://radleymarx.com/blog/simple-guide-to-9-patch/
How do I take into consideration the always there android top
navigation bar and the possible use of advertisements at the bottom?
you can put a linear layout which has the ad on the bottom , and once it will be shown , the upper view will shrink its size.
about the action bar on the top, it doesn't matter , since the layout is below it anyway.
if you wish, you can also hide the top bar. however , if you have the bottom navigation bar (as on honeycomb and some ice-cream sandwich devices ) , you can't just hide it , since the end user must be able to press the back and home buttons .
Do they just cover the design or do they change the resolution?
you (and also those components) can't change resolution just like on a PC . everything takes space depending on your code and layout.
it seems that you need some guidelines of how to design for android. may i suggest checking out those links:
http://developer.android.com/design/index.html
http://www.google.com/events/io/2011/sessions/designing-and-implementing-android-uis-for-phones-and-tablets.html
http://www.google.com/events/io/2011/sessions/honeycomb-highlights.html
On Android the user can place a widget on the desktop and then to move it by long touch and moving the finger while still holding.
Is it possible to programmatically get the position on the screen where the widget was moved by long touch?
I need my desktop widget to know if it's near the edge of the screen of the device. Depending on whether it's on the top of the desktop or at the bottom different layouts for the widget will be chosen.
I would expect that this position is not given in pixels, but as pair of 0-based indexes. E.g. if the device can display 4x7 cells on the desktop, the widget in the bottom-right corner should have coords (3, 6). Also it should be somehow possible to ask the device how many cells fit into the screen.
Or am I misunderstanding something?
On Android 2.1 and later, with some select home screens, you can find out where an app widget resides when it is clicked via getSourceBounds() -- this value is attached to any Intent you spawn via a PendingIntent via setOnClickPendingIntent().
However:
this only works on Android 2.1 and newer
not all home screens might do this, as this is part of the Launcher code IIRC
the coordinates are in pixels IIRC
there is no way to interrogate the home screen to find out this information any other way, since there is no API to interact with the home screen
Hence, I think your stated goal ("Depending on whether it's on the top of the desktop or at the bottom different layouts for the widget will be chosen") is impossible, I think.