Reputation: 1570
Why does my Android layout work when I use Buttons with a background, but break when I use ImageButtons? I have read through the documentation and cannot figure out why they render differently. I see that one is a TextView and that one is an ImageView but I assume a dp is a dp regardless of the context. Between the two layouts the only thing that I have changed is "ImageButton" to "Button" and "src" to "background".
Working layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/background">
. . .
<Button
android:contentDescription="@string/login_button_facebook"
android:layout_width="200dp"
android:layout_height="45dp"
android:background="@drawable/first_thought_menu_2_facebook"
android:onClick="loginWithFacebook"
/>
<Button
android:contentDescription="@string/login_button_email"
android:layout_width="200dp"
android:layout_height="45dp"
android:background="@drawable/first_thought_menu_3_email"
android:onClick="loginWithEmail"
/>
<Button
android:contentDescription="@string/login_button_anonymous"
android:layout_width="200dp"
android:layout_height="45dp"
android:background="@drawable/first_thought_menu_4_anonymous"
android:onClick="loginWithAnonymous"
/>
. . .
</LinearLayout>
Picture of working layout:
Broken layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/background">
. . .
<ImageButton
android:contentDescription="@string/login_button_facebook"
android:layout_width="200dp"
android:layout_height="45dp"
android:src="@drawable/first_thought_menu_2_facebook"
android:onClick="loginWithFacebook"
/>
<ImageButton
android:contentDescription="@string/login_button_email"
android:layout_width="200dp"
android:layout_height="45dp"
android:src="@drawable/first_thought_menu_3_email"
android:onClick="loginWithEmail"
/>
<ImageButton
android:contentDescription="@string/login_button_anonymous"
android:layout_width="200dp"
android:layout_height="45dp"
android:src="@drawable/first_thought_menu_4_anonymous"
android:onClick="loginWithAnonymous"
/>
. . .
</LinearLayout>
Picture of broken layout:
Upvotes: 0
Views: 460