I am developing an accessibility service on android and I want to check the space between on-screen elements. Currently I am already using AccessibilityNodeInfo and its getBoundsInScreen() method to read the touch target size of clicked elements.
Do you know if there is a way to retrieve the margin of an element?
There is not. Anything that you came up with would be a hack.
You could compare the on screen coordinates of elements. But, then you're not going to get a "margin" just the space between them. There is no way to get a "margin" property.
Related
I'm stuck and I think wisdom (aka experience) is the only solution.
I need to be able to have boxes on a screen with data inside each box. The number of boxes on the screen needs to be able to change and the boxes need to scale accordingly (as well as the text data inside of them) to allow for the additional boxes.
Example: I might start with only 8 boxes which are evenly spaced and displaying data at a reasonable font scale.
As I add more boxes I need the rest of the boxes to scale down and allow everything on one screen.
I am currently attempting to use a TableLayout, but I'm not certain how to make everything scale correctly. Also, I'm generating everything programmatically by extending the TableLayout. Can someone point me in the right direction. Is there a better layout method that I'm not seeing? I'm sure I'm not the first person to need this, so are there examples available that I'm just not finding by searching?
The eventual solution was to build my own scaling function which took screen pixel dimensions and calculated the appropriate margin offsets to use on a relative layout. It requires a complete redraw each time the scaling factor changes, which is annoyingly resource intensive.
I am working on an Android Advertisement SDK. This SDK will charge fetch Advertisement resource and play it in a WebView.
Depending on the content of the Advertisement, the SDK need to change the WebView's position and size. For Example, A banner advertisement will palce in the top or bottom of screen, some advertisement maybe place at center, left or right.
Now I need the users to place the WebView in FrameLayout, So I could change the position and size of WebView at will and don't affect other views. I could set FrameLayout.LayoutParameters to adjust position and size.
Obviously, this is a strong restriction for users. Maybe they want use RelativeLayout and others.
So is there anyone have ideas about my issue? I am trying to use fragment now and didn't know would it work.
There is 2 approach to do this.
One is to set a layout ( forgot the name ) which allows you to set a component at custom position, size anywhere you want. As I remember it was 2 of those and one is deprecated form a version of Android. Google it those please, if you choose this method.
Other one it is with a trick:
Establish 9 positions (like the 9 pinch) and there use a predefined layout.
For eg. use a Relative layout.
1. if the banner need to be in position 1 than do x,y,z stuff - rearrange a bit the others, do what you need if is on the top left.
2. if the banner it is a "merged position" 1 and 2 from grid (a a lot wider), than you do other corrections.
and do many cases what you need.
Good luck
I have figure out this question.
Every android app is base on a FrameLayout(android.R.id.content).When I need to change position of a view. I could remove the view from its current layout and add it to FrameLayout(android.R.id.content).
That's what I want.
Is that ok to use absolute layout in my application if i know exactly the x,y that i'll draw the widget at or it'll affect the application appearance on the device ?
I'm asking this question as I've read that it's deprecated
Even if you know exactly where you want to put each widget, you won't know the exact resolution of the devices which will run your application. Some will have empty space left on the screen, while others might not have room to display all your widgets.
Short version: better not use it, there are always better options.
In case of absolute layout, your application will adjust itself in every phn ,of any resolution or screen size. But in case of fixed coordinates may be screen size becomes a limitation.
It is a very bad practice to use absolute layout coordinates.
Don't use it.
I have to create a UI with components(TextView, Bottons etc) placed at particular coordinates as specified in an XML coming from a server. I am currently using AbsoluteLayout but since its deprecated i want to use some other method.
Use FrameLayout, this way you can position x/y exact anywhere using the margin (i.e. marginTop, marginLeft) properties of the components.
http://developer.android.com/reference/android/widget/FrameLayout.html
You can use the AbsoluteLayout. There you can set the exact coordinates of the UI element. However, I would no really recommend to use in any situation, because you can get in trouble with different screen size/resolution.
I want o be able to add items to my layout, and set the exact position of these items.
x,y,width,height.
I am currently using AbsoluteLaout which is deprecated, is there any other layout that allows me to locate objects on the screen, by specifying their x,y?
I also need to be able to read the x,y of all these objects on the screen.
I already use getLeft(), and getTop().
You can use RelativeLayout and set margins to position. This is going to kill various screen size compatibility.