Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android XML样式_Android_Xml - Fatal编程技术网

Android XML样式

Android XML样式,android,xml,Android,Xml,我的styles.xml中有一个切换按钮正在使用的以下样式。但是,我希望切换按钮填充父对象,但不拉伸图像。我如何告诉它将背景图像居中而不是拉伸它?我试图增加用户可以点击的区域 切换: <ToggleButton android:id="@+id/OtherToggle" android:layout_width="fill_parent" android:layout_height="fill_parent" style="@style/OtherToggl

我的styles.xml中有一个切换按钮正在使用的以下样式。但是,我希望切换按钮填充父对象,但不拉伸图像。我如何告诉它将背景图像居中而不是拉伸它?我试图增加用户可以点击的区域

切换:

<ToggleButton
    android:id="@+id/OtherToggle"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    style="@style/OtherToggle" />
风格:

<style name="OtherToggle">
    <item name="android:textOn">""</item>
    <item name="android:textOff">""</item>
    <item name="android:disabledAlpha">?android:attr/disabledAlpha</item>
    <item name="android:background">@drawable/other_toggle_bg</item>
</style>

我想你的意思是你确实想拉伸图像,但是你想保持纵横比不变

如果是,请尝试将此添加到您的样式中:

<item name="android:scaleType">centerInside</item>

如果centerInside不符合您的要求,则可以使用其他选项。

也许您可以使用图层列表作为可用于切换按钮的背景绘图?创建以下xml文件并在android中使用:background属性:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+android:id/background"  
      android:drawable="@android:color/transparent" />
<item>
<bitmap android:src="@drawable/other_toggle_bg"
      android:gravity="center" />
</item>
</layer-list>

不,我不想拉伸它,保持其原始大小或更小的内部居中。请参阅我对您的问题的评论,如上所述。如果您希望图像居中且永远不会变大,但在必要时收缩,而不更改宽高比以完全显示在按钮内,我不认为Android中有一种内置的方法可以做到这一点。您应该能够通过编程实现这一点,尽管您自己是这样做的。