So... a known Android
issue is that setting a drawable
background to a TextView
in conjunction with setting the padding
(e.g. paddingLeft
) will only work if the background
is set before the padding
.
So far so good (and annoying).
But, what if I want to do it via .xml (and not programmatically)? :(
Any ideas?
Here is what I want:
Image may be NSFW.
Clik here to view.
But no matter what paddingLeft
I set, nothing changes.
I'm positive it should work, but maybe it's a layout bug?
Here is the (very simplified) layout:
<RelativeLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"><Button android:id="@+id/call" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:background="@drawable/call_btn" android:paddingLeft="@dimen/DESIRED_LEFT_PADDING" android:paddingStart="@dimen/DESIRED_LEFT_PADDING" android:drawableLeft="@drawable/ic_phone" android:drawablePadding="@dimen/drawable_padding" android:drawableStart="@drawable/ic_phone" android:singleLine="true" /><Button android:id="@+id/address" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/call" android:paddingLeft="@dimen/rest_item_btn_side_margin" android:paddingStart="@dimen/rest_item_btn_side_margin" android:background="@drawable/navigate_btn" android:drawableLeft="@drawable/ic_address" android:drawablePadding="@dimen/drawable_padding" android:drawableStart="@drawable/ic_address" android:gravity="start|center_vertical" android:singleLine="true" /> </RelativeLayout>
And this layout lies within another one, using the <include>
tag:
<CoordinatorLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:fitsSystemWindows="true"><ScrollView android:id="@+id/scrollview" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/appbar" app:layout_behavior="@string/appbar_scrolling_view_behavior" android:background="@android:color/transparent"><RelativeLayout android:layout_width="match_parent" android:layout_height="0dp" android:background="@android:color/transparent"><include android:id="@+id/btn_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" layout="@layout/btn_layout" /></RelativeLayout></ScrollView></CoordinatorLayout>
Solution
Well, that is awkward, but I just had a global Button
style
setting paddingLeft
... I was sure an xml declaration overrides style
... Apparently not always. Is it a bug or shouldn't I trust this behavior?
Anyway, issue finally solved:)