How can I get the position of a view in an AbsoluteLayout?

Can anyone give me a tip for how to get the position of a view what is a child of an AbsoluteLayout? I want to do this for drag and drop the selected view.

Thank you!


Asked by: Lucas749 | Posted: 24-01-2022






Answer 1

AbsoluteLayout is deprecated, so probably you would have to provide your own drag&drop layout by extending ViewGroup. In general, layout it is responsible for positioning children widgets. This is done in onLayout() method which you would have to override. It will be probably something like this:


protected void onLayout(boolean changed, int l, int t, int r, int b) {
   final int count = getChildCount();
   for(int i=0; i<count; i++){
      final View child = getChildAt(i);
      if(GONE != child.getVisibility()){
        //position child
        child.layout(left, top, right, bottom);
      }
   }
}

So, by implementing your own DragAndDropLayout - you know the position of your children. But, maybe there is simplier solution.
Regards!

Answered by: Adelaide119 | Posted: 25-02-2022



Answer 2

To know where a child is in its parent, simply call getLeft() and getTop(). Also, do not use AbsoluteLayout :)

Answered by: John328 | Posted: 25-02-2022



Similar questions

Using the deprecated AbsoluteLayout class in Android?

The AbsoluteLayout class is deprecated but still can write it in code and it works. Will there be any problems if I use this class? Will the application work correctly after I deploy it on a phone? Thanks


Alternative to AbsoluteLayout in Android?

If AbsoluteLayout is deprecated what can I use instead of it? I've done an app that uses AbsoluteLayout but it doesn't work well with the different screen resolutions. I use because I can set the X and Y position of a button. Can I set the position of a button using another layout?


android - Create a push notification icon without AbsoluteLayout

I want to create a icons with texts and also have an unread count on right corner like this one I have made this by using AbsoluteLayout, but it is deprecated... How else it is possible to do this?


android - Why method AbsoluteLayout gets overlined?

I want to set XY position of imageView but method AbsoluteLayout gets overlined like in code below: final ImageView animal = (ImageView)findViewById(R.id.imageView1); animal.setLayoutParams(new &lt;span style="text-AbsoluteLayout.LayoutParams(animal.getWidth(),animal.getHeight(), x1,y1)); http://i.imgur.com/1QBAL.png


android - why absolutelayout is deprecated?


android - Alternative to AbsoluteLayout

the question "What is a usefull alternative to AbsoluteLayout?" seems to be a question which is often asked, but never really answered. My situation is as follows: I want to position Circles (for the sake of simplicity i used RadioButtons for testing) so that the distances between the circles are proportional on all possible display sizes. Also i need to know the position of the circles to match on...


Android: how to change layout_x, layout_y in an AbsoluteLayout dynamically?

I have a fixed background-image and showing another image on top of it. Here is the xml- &lt;AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" &gt; &lt;ImageView android:id="@+id/test_image" android:src="@drawable/lpch_1" android:layout_width="fill_pa...


java - ImageView within an AbsoluteLayout, How to set x, y coordinates of the ImageView?

What I'm trying to do is create a poorman's version of a gps map. I've setup a "map" picture as the background of an AbsoluteLayout, and then created a tiny 20x20 square picture that I need to move to different coordinates. How do I go about doing this in the Java code? &lt;AbsoluteLayout android:id="@+id/llMapContainer" android:layout_width="match_parent" android:layout_height="390dp" andr...


android - How to draw endless 2D board/map if AbsoluteLayout is deprecated?

I wish to draw endless board like game world map of endless cell grid. User will be able to scroll it, but the data will be stored in memory, not on scree. I.e. I will populate cells when they are appear on screen and delete them on hide. How to implement this in Android? In javascript and java I would use 2 nested absolute panes or divs with no clipping.


android - Valid alternatives of AbsoluteLayout

I'm updating an application where the user should be able to drag and drop some elements (buttons/imagebuttons) so that they change position, and I also need to get their X,Y coordinates. In the previous versions I used AbsoluteLayout, even if deprecated. What could I use instead of it? Is there a real substitute?






Still can't find your answer? Check out these communities...



Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android



top