2017-04-07 2 views
1

Ich habe ToggleButton umgesetzt Bild anstelle von Text zu verwenden, aber wie maßstabs ich sieAndroid Studio | Wie skaliere ich das Bild in ToggleButton?

Ich habe mit scaleType versucht, aber arbeiten nicht

ic_toggle.xml (ich versucht habe scaleType hier zu verwenden, aber nicht funktionieren)

<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> 

Originalbild

enter image description here

Hier ist Ergebnis, das ich bekam.

enter image description here

Antwort

3

dieses versuchen

<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" /> 

+0

Es ist nicht mein Bild Arbeits skaliert noch nicht. Aber ich weiß nicht warum, wenn ich das Bild auf das Quadrat setze, warum das Bild immer noch verzerrt ist? – TacticalBacon

Verwandte Themen