0

I have a toolbar with a LinearLayout inside (I painted the LinearLayout background in black so you can see it better). Inside the LinearLayout I have 3 ImageButtons.

enter image description here

As you can see, in the android studio graphic editor I've selected the first button, and with the selected area we can see that the height is matched with the LinearLayout height and the width is 1/3 of the toolbar width, it's ok!

However, the ImageButton itself (the grey area with the play image) is not matching the selected region, it seems to have some padding, and this is what I want to fix!

I want this (for the three buttons):

enter image description here

Here is my toolbar xml:

<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
android:elevation="4dp"
android:layout_alignParentBottom="true">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="3"
    android:background="@android:color/black"
    android:orientation="horizontal">

    <ImageButton
        android:id="@+id/playButton"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:scaleType="center"
        android:clickable="true"
        android:src="@drawable/ic_play" />

    <ImageButton
        android:id="@+id/stopButton"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:scaleType="center"
        android:clickable="true"
        android:src="@drawable/ic_stop" />

    <ImageButton
        android:id="@+id/bookmarkButton"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:scaleType="center"
        android:clickable="true"
        android:src="@drawable/ic_bookmark" />

</LinearLayout>


</android.support.v7.widget.Toolbar>

What I've tried:

Setting android:padding="0dp" in the LinearLayout.. But nothing changed.

yat0
  • 967
  • 1
  • 13
  • 29
  • have you tried giving scaleType="fitXY" – Aakash Sep 02 '15 at 22:04
  • possible duplicate of [How can I stretch the image in imagebutton to the whole area of the imagebutton?](http://stackoverflow.com/questions/14875705/how-can-i-stretch-the-image-in-imagebutton-to-the-whole-area-of-the-imagebutton) – cybersam Sep 02 '15 at 22:13
  • @cybersam it's not duplicated, sorry for misunderstanding. – yat0 Sep 02 '15 at 23:21

2 Answers2

4

Try adding this style to your ImageButton, hope this is what you want

style="?android:attr/borderlessButtonStyle"

like this

<ImageButton
    android:id="@+id/playButton"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:scaleType="center"
    android:clickable="true"
    android:src="@drawable/ic_play"
    style="?android:attr/borderlessButtonStyle"/>
Derek Fung
  • 8,171
  • 1
  • 25
  • 28
0

Change

android:scaleType="centerCrop"

and add

android:background="@android:color/transparent" 

for each ImageButton

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar_bottom"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:contentInsetLeft="0dp"
    app:contentInsetStart="0dp"
    android:elevation="4dp"
    android:layout_alignParentBottom="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="3"
        android:background="@android:color/black"
        android:orientation="horizontal">

        <ImageButton
            android:id="@+id/playButton"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:scaleType="centerCrop"
            android:clickable="true"
            android:padding="0dp"
            android:src="@drawable/ic_action_email" />

        <ImageButton
            android:id="@+id/stopButton"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:scaleType="centerCrop"
            android:clickable="true"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_action_email_blue" />

        <ImageButton
            android:id="@+id/bookmarkButton"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:scaleType="centerCrop"
            android:clickable="true"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_action_email" />

    </LinearLayout>


</android.support.v7.widget.Toolbar>
Fareya
  • 1,523
  • 10
  • 11