Search code examples
androidimagebuttonremoteview

ImageButton in RemotesView stretches


I'm making an application which shows a customized notification bar. The problem I'm facing is the ImageButtons in the view are stretched horizontally.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="horizontal"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:weightSum="4" android:gravity="center_horizontal">

    <ImageButton
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:id="@+id/a"
            android:scaleType="centerInside"
            android:background="@drawable/a"/>
    <ImageButton
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:id="@+id/b"
            android:scaleType="centerInside"
            android:background="@drawable/b"/>
    <ImageButton
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:id="@+id/c"
            android:scaleType="centerInside"
            android:background="@drawable/c"/>
    <ImageButton
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:id="@+id/d"
            android:scaleType="centerInside"
            android:background="@drawable/d"/>
</LinearLayout>
..
RemoteViews rv = new RemoteViews(getPackageName(), R.layout.notification);
notification.contentView = rv;  

The size of images I used is 72x72. The images are even worse when my device is tilted to landscape mode as the images tend to fill up the notification bar.
Is there a way to make sure images are scaled(down) uniformly and also leave some spaces between each ImageButton to make the notification look better?


Solution

  • To anyone who has similar question, the solution is to fitCenter instead of centerInside in the android:scaleType attribute.