I am trying to lay buttons on top of an image that is used as the background for multiple devices/screen sizes. If I define the button in a relativeLayout for a device with an aspect ratio of 9:16 (e.g. Galaxy Nexus or Nexus 5) so that the button aligns with a specific spot on the image, then it doesn't line up with the same image on a device with an aspect ratio of 3:5 (e.g. Nexus S). In my relative layout, the first button is aligned to the left and bottom of the screen with an offset (e.g. android:layout_marginLeft="32dp" and android:layout_marginBottom="150dp"). All other buttons are aligned to this button.
I have spent days trying to figure this out with experimentation and searching for tutorials, but nothing seems to work.
The following image is for the Nexus 5. As you can see, the buttons line up with the background:
The following image is for the Nexus S. As you can see, the buttons are offset from the background
EDIT: I am obviously missing some key concept. I have separate directories for each screen density of hdpi, xhdpi, and xxhdpi. But, based on my two attached images, it seems I need to have a separate layout for screens with dimension 480x800 versus 720x1280 and 1080x1920. It seems that the screen of 720x1280 must require the same layout as the 1080x1920 screen because the Nexus 5 and the Galaxy Nexus have the same result (i.e. as seen in the first image). To create a separate layout, I've tried using layout-small, layout, layout-large, etc. (which is the deprecated approach), as well as layout-sw480dp and layout-sw720dp. Then, the layout_marginLeft and layout_margin_bottom of the first button is adjusted for the appropriate screen size. Neither of these approaches works.
Here is the current content of my layout for the first image:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingLeft="15dp"
android:paddingBottom="5dp"
tools:context="com.myCompany.myApp.MainActivity"
android:background="@drawable/android_home_screen">
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:text="Channel 1"
android:id="@+id/channel1"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:textColor="#FFFFFF"
android:layout_marginBottom="145dp"
android:layout_marginLeft="17dp"
android:lines="2" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:text="Channel 3"
android:id="@+id/channel3"
android:textColor="#FFFFFF"
android:layout_marginLeft="0dp"
android:layout_toRightOf="@+id/channel1"
android:layout_alignTop="@+id/channel1"
android:lines="2" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:text="Channel 5"
android:id="@+id/channel5"
android:textColor="#FFFFFF"
android:layout_marginLeft="0dp"
android:layout_toRightOf="@+id/channel3"
android:layout_alignTop="@+id/channel3"
android:lines="2" />
...
</RelativeLayout>
Please help me understand how to place buttons on top of specific spots of an image regardless of the screen size/aspect ratio/density of the screen. Specifically, please provide an example of how to define a button that appears on the same visual spot of a background image for screen sizes of 480x800 and 720x1280.
The following is a full image of the screen background. I am trying to place buttons on top of the areas with a thin gold outline. There is one of these in each of the drawable directories for hdpi, xhdpi, and xxhdpi. The hdpi image is 480x693 pixels, the xhdpi image is 720x1040 pixels, and the xxhdpi image is 1080x1559 pixels with respective resolutions of 213.34 ppi, 320 ppi, and 480 ppi. These resolutions and dimensions enable the images to have the same image size (width and height) in terms of points.