1

I'm trying to stick some ImageButtons on specific positions on ImageView. the problem is that i have to use absolute layout for the ImageButtons, and when I change the screen resolution all the ImageButtons moving from their places.

I've looking for an answer in all the web and just can't find anything.

Thank you.

user2181452
  • 309
  • 1
  • 4
  • 7
  • 1
    Simply put don't use AbsoluteLayout its depreceated.. http://androidforums.com/application-development/100800-absolutelayout-deprecated.html – cjds Apr 19 '13 at 10:26
  • @user2181452 could you please show us what you have tried? – Sankar V Apr 19 '13 at 10:45

2 Answers2

0

I recommand you to not use absolute position in your layout. Use containers and some margins if you can to put your buttons at the right position.

If you really need absolute position depending on device, you can use specific dimensions for each kind of resolution. See here:

http://developer.android.com/training/basics/supporting-devices/screens.html

Aerilys
  • 1,628
  • 1
  • 16
  • 22
  • But if I use margins (dp) to position the buttons it will change in different resolution – user2181452 Apr 19 '13 at 10:36
  • Yes. That's why you will have to change these margins for each resolution if you want absolute positionning. That's also why I recommand you to not use absolute positionning. – Aerilys Apr 19 '13 at 10:40
0

Just use relative layout instead of absolute layout. if you dont like relative layout, you may use absolute layout, there is nothing wrong with it, its just not practical in most situations. You may use absolute layout and scale the views on the screen with something like this: Scale a view and its layered subviews relatively

Dianne Hackborn (works at google) says:

I'll say again: we are not going to remove AbsoluteLayout from a future release, but we strongly discourage people from using it.

If you choose to not believe me, you are welcome to, but I am not responsible for you making that decision.

This is how to overlay buttons:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/image" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="34dp"
        android:layout_marginRight="40dp"
        android:text="Button" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/button2"
        android:layout_below="@+id/button1"
        android:layout_marginRight="37dp"
        android:layout_marginTop="108dp"
        android:text="Button" />

</RelativeLayout>
Community
  • 1
  • 1
string.Empty
  • 10,393
  • 4
  • 39
  • 67