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

I have a fixed background image and another image is shown on top of it. Here is the xml -

<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" > <ImageView android:id="@+id/test_image" android:src="@drawable/lpch_1" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <ImageView android:id="@+id/search_pin" android:src="@drawable/pin" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_y="100px" android:layout_x="100px" /> </AbsoluteLayout> 

Now, how can I change the layout_x, layout_y of the search_pin id image from the code?

+4
source share
3 answers

Try the following:

 AbsoluteLayout.LayoutParams params = ((AbsoluteLayout.LayoutParams) test_image.getLayoutParams()); params.x = 100; params.y = 100; test_image.setLayoutParams(params); 
+5
source

The absolute layout is out of date.

In this case, I would suggest using FrameLayout .

One more thing: dp or dip is preferable to px .

Since Android support supports multiple screen resolutions, it's not good to mention fixed coordinates for a particular widget.

+3
source

You should use Absolutelayout instead of relativelayout :

android:layout_x="100dp" not px

android:layout_y="100dp"

both are used for Absolutelayout .

0
source

All Articles