bigjoe1 bigjoe1 - 12 days ago 5
Android Question

ImageButtons on ImageView [Android]

I want to put ImageButtons on ImageView: enter image description here
I tried to do this with linear layout but always buttons appearing under imageview. How can i do this?

Thanks in advance!

Answer

Here is an example in xml. I hope it helps (See screenshot at the bottom)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">


<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/imageView2"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:src="@drawable/pc"
        android:scaleType="fitXY" />

    <ImageButton
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:id="@+id/imageButton"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginLeft="47dp"
        android:layout_marginStart="47dp"
        android:src="@drawable/phone"
        android:scaleType="fitXY" />

    <ImageButton
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:id="@+id/imageButton2"
        android:layout_alignBottom="@+id/imageButton"
        android:layout_centerHorizontal="true"
        android:src="@drawable/phone"
        android:scaleType="fitXY" />

    <ImageButton
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:id="@+id/imageButton3"
        android:layout_alignTop="@+id/imageButton2"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_marginRight="36dp"
        android:layout_marginEnd="36dp"
        android:src="@drawable/phone"
        android:scaleType="fitXY" />
</RelativeLayout>
</RelativeLayout>

Screenshot

Comments