Waqas Khan Waqas Khan - 3 months ago 9
Android Question

Image Buttons are not displaying on same position on different devices, eg : having API level =16

I am having an issue on displaying buttons (Previous (@id/ib1) ,Next (@id/ib2)) on same position for different devices.
The Buttons are slightly below device(Motorola Droid Razr 4.1.2 Api level 16).
XML is as Follows

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/firstLay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@drawable/bckgrd"
android:gravity="center">

<LinearLayout
android:id="@+id/layalif"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10">

<LinearLayout
android:id="@+id/layalif1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="3.2"
android:orientation="vertical">

<ImageView
android:id="@+id/ivalif1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:src="@drawable/alifmadstatic" />
</LinearLayout>

<LinearLayout
android:id="@+id/layalif2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2.3">

<ImageView

android:id="@+id/ivalif2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layerType="none"
android:scaleType="fitXY"
android:src="@drawable/backgroundmove" />
</LinearLayout>

<LinearLayout
android:id="@+id/layadd"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="4.5">


</LinearLayout>


</LinearLayout>

<pro.photex.com.testpoint.drawalifmadaa
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layerType="software"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />


<ImageButton
android:layout_width="64dp"
android:layout_height="48dp"
android:scaleType="centerInside"
android:id="@+id/ib1"
android:layout_marginLeft="0dp"
android:src="@drawable/previews"
android:onClick="btnpreviousclick"
android:background="@color/Transparent"
android:layout_marginBottom="70dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<ImageButton
android:layout_width="64dp"
android:layout_height="48dp"
android:scaleType="centerInside"
android:id="@+id/ib2"
android:src="@drawable/next"
android:background="@color/Transparent"
android:onClick="btnnxtonclick"
android:layout_alignTop="@+id/ib1"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

</RelativeLayout>


Here's the output image Api level 16 (screen density 1.5):

[enter image description here

Here's the output image Api level 21 (screen density 1.5):

enter image description here

Rah Rah
Answer

add

android:layout_alignBottom="@+id/layalif" in your both ImageButton

and remove

android:layout_marginBottom="70dp"