Android Studio |如何在ToggleButton中缩放图像? [英] Android Studio | How do I scale the image in ToggleButton?
本文介绍了Android Studio |如何在ToggleButton中缩放图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经实现了ToggleButton以使用图像而不是文本,但是如何缩放它们
I have implemented ToggleButton to use image instead of text but how do I scale them
我尝试使用 scaleType
,但不起作用
I have tried using scaleType
but not work
ic_toggle.xml (我也尝试过在这里使用 scaleType
,但不起作用)
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>
原始图片
这是我得到的结果.
推荐答案
尝试一下
<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" />
这篇关于Android Studio |如何在ToggleButton中缩放图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文