3

I have implemented ToggleButton to use image instead of text but how do I scale them

I have tried using scaleType but not work

ic_toggle.xml (I have tried using scaleType here too but not work)

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_checked="false"
          android:drawable="@drawable/ic_signal_p1"/>

    <item android:state_checked="true"
          android:drawable="@drawable/ic_signal_p2" />

</selector>

fragment_deviceitem_list.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">

    <ToggleButton
        android:id="@+id/scan"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/ic_toggle"
        android:scaleType="fitCenter"
        android:layout_margin="10dp"
        android:textOn=""
        android:textOff=""
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:layout_centerVertical="true"/>

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="63dp"
        android:layout_alignParentBottom="true"
        android:visibility="visible" />

</RelativeLayout>

Original Image

enter image description here

Here's result I got.

enter image description here

phwt
  • 1,356
  • 1
  • 22
  • 42

1 Answers1

1

try this

<ToggleButton
    android:id="@+id/scan"
     android:layout_width="30px"
     android:layout_height="30px"
    android:background="@drawable/ic_toggle"
    android:scaleType="fitCenter"
    android:layout_margin="10dp"
    android:textOn=""
    android:textOff=""
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:layout_centerVertical="true"/>

<ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:visibility="visible" />

Santosh Bachkar
  • 460
  • 4
  • 14
  • It's not working my image still not scaled. But I don't know why when I set image to square why image is still distorted? – phwt Apr 07 '17 at 15:26