4

I have a fixed background-image and showing another image 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 image-id search_pin from code?

SBerg413
  • 14,515
  • 6
  • 62
  • 88
Avisek Chakraborty
  • 8,229
  • 10
  • 48
  • 76

3 Answers3

6

Try this:

AbsoluteLayout.LayoutParams params = ((AbsoluteLayout.LayoutParams) test_image.getLayoutParams());
params.x = 100;
params.y = 100;
test_image.setLayoutParams(params); 
Peter Knego
  • 79,991
  • 11
  • 123
  • 154
3

Absolute Layout is deprecated.

For this case, i would suggest to use FrameLayout.

One more thing, dp or dip is more preferrable other than px.

As android support multiple screen resolutions, its not good to mention fixed co-ordinates for a particular widget.

Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
0

You must use Absolutelayout intead of relativelayout:

android:layout_x="100dp" not px

android:layout_y="100dp"

both used for absolutelayout.

Muhammed Refaat
  • 8,914
  • 14
  • 83
  • 118
AyAz
  • 2,027
  • 2
  • 21
  • 28