Rafael
Rafael

Reputation: 3122

ImageButton is overlapping another ImageButton

I have this layout on preview

enter image description here

With this code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/actionbar_background"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingRight="10dp" >

<ImageButton
    android:id="@+action_bar_documentos/btn_menu"
    android:layout_width="48dp"
    android:layout_height="48dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="5dp"
    android:adjustViewBounds="true"
    android:background="@drawable/list_selector_action_bar"
    android:contentDescription="@string/app_name"
    android:cropToPadding="false"
    android:onClick="menu"
    android:scaleType="center"
    android:src="@drawable/menu" />

    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+action_bar_documentos/btn_menu" >

        <ImageButton
            android:id="@+action_bar/btn_camera"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="false"
            android:layout_toRightOf="@+action_bar/btn_menu"
            android:background="@drawable/list_selector_action_bar"
            android:contentDescription="@string/app_name"
            android:onClick="btnCamera"
            android:scaleType="centerCrop"
            android:src="@drawable/img_camera" />

        <ImageButton
            android:id="@+action_bar_documentos/btn_search"
            android:layout_width="48dp"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_alignParentBottom="true"
            android:layout_toRightOf="@+action_bar_documentos/btn_camera"
            android:background="@drawable/list_selector_action_bar"
            android:contentDescription="@string/app_name"
            android:onClick="filtro"
            android:paddingBottom="5dp"
            android:paddingLeft="3dp"
            android:paddingRight="3dp"
            android:paddingTop="3dp"
            android:scaleType="centerCrop"
            android:src="@drawable/btn_filtro_top" />

    </RelativeLayout>....

It's look fine, for now. But when I run my app, the layout become:

enter image description here

There is any problem with screen size? Or the problem is on my xml code?

Thank you, and sorry by grammar mistakes.

Upvotes: 0

Views: 99

Answers (1)

Tenfour04
Tenfour04

Reputation: 93922

Your btn_camera should not be toRightOf btn_menu because btn_menu is not inside the same RelativeLayout. Instead, btn_camera should use alignParentLeft="true".

Alternatively, you could move btn_camera inside the nested RelativeLayout.

Also, as @epsilondelta commented, your btn_search is referencing the wrong namespace for the id of btn_camera. Sometimes, errors like this don't get caught in the editor layout view until you close and reopen the xml file.

Upvotes: 4

Related Questions