When is / was the AbsoluteLayout used?

0

I know that with this layout it is possible to manually set the x and y posits of the components inserted in the layout .

In what hypothesis is / was it recommended to use AbsoluteLayout , since it works with fixed coordinates in the plane, which makes it impossible to see Activity in other resolutions?

In the version of Android Studio I use (Windows / 2.3), when I try to use this layout , the IDE brings me a message saying it is considered obsolete. Is there any alternative to this layout ?

    
asked by anonymous 16.03.2017 / 03:52

1 answer

1

AbsoluteLayout , as you started to mention, allows you to specify the exact location of your children. The location of the views can be specified using the and % attributes attributes with both% and% x ( density independent pixels ). Absolute positioning is not very useful in the world of millions of screen resolutions and aspect ratios, perhaps for this reason it has become obsolete.

The perhaps more viable alternative to replacing y would be FrameLayout , where in general, you can add a view in a specific position containing as attributes dip and dp , which would basically serve as your coordinates. Let's say you need to use an image of size AbsoluteLayout in position leftMargin , so you would have something like this:

Java

FrameLayout frame = (FrameLayout)findViewById(R.id.frame);
ImageView iv = new ImageView(this);
iv.setBackgroundColor(Color.BLUE);    
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(40, 40);
params.leftMargin = 100;
params.topMargin  = 80;
frame.addView(iv, params);

XML

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/frame"
    android:background="#FFFF"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</FrameLayout>

The image below illustrates the view regarding topMargin and spacing. See:

Ifound this answer in the global OS that suggests as 40x40 , but particularly perhaps, say maybe, not is a good option because there are resources of 80x100 , so to say, that basically would be unusable, making it not the best alternative. Analogously you would be taking Swiss Army Knife to the bar just to use beer opener.

    
16.03.2017 / 04:53