2

I'm having issues with my Activity and an ImageButton inside it. It looks like it is clipping:

enter image description here

This is the XML of the corresponding activity:

<?xml version="1.0" encoding="utf-8"?>
<!-- A RecyclerView with some commonly used attributes -->
<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:id="@+id/todo_linear_layout"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:orientation="horizontal">

    <ImageButton
        android:id="@+id/imageButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        app:srcCompat="@android:drawable/ic_input_add" />

    <EditText
        android:id="@+id/edittodo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20px"
        android:layout_weight="5"
        android:textColor="@android:color/black" />
</LinearLayout>

<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/todo_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" >

</android.support.v7.widget.RecyclerView>
</LinearLayout>

Additionally the Layout Designer in Android Studio shows the Layout correctly:

enter image description here

Where is the problem here? I already tried to change margin or padding values but the Button is still clipping in the running app on my android device.

Onik
  • 19,396
  • 14
  • 68
  • 91
NKnuelle
  • 234
  • 2
  • 19

2 Answers2

1

I believe that what's happening is that the device you're running your app on doesn't have the @android:drawable/ic_input_add drawable.

I tried running the code you posted, and everything worked for me. However, if I delete the app:srcCompat attribute from the <ImageButton> tag, then I get the same behavior you posted in your first screenshot.

In general, you can't rely on 100% of devices having @android: resources. Some manufacturers remove resources, and others replace the values with nonsense (I've seen @android:color/white come through as gray, for example).

I recommend creating your own drawable (maybe even just manually copying the one from Android and adding it to your project), and referencing that instead.

app:srcCompat="@drawable/your_own_add"
Ben P.
  • 52,661
  • 6
  • 95
  • 123
  • This seems to be the issue. I'll give it a try tomorrow. I never thought, that android ressources could not be present on an Android device. It actually sounds strange – NKnuelle Sep 25 '18 at 20:28
0

Changing the app:srcCompat to: android:src="@android:drawable/ic_input_add" did it! So the issue was, that the device didn't find that icon and displayed just something gray.

NKnuelle
  • 234
  • 2
  • 19