android - 选择器的大小与 "normal"图像不同

标签 android image selector drawable

我有一个奇怪的问题。当我这样做时:

btnSleeping.setImageDrawable(getResources().getDrawable(
                        R.drawable.selector_sleeping_on));

图像比我这样做时要小:btnSleeping.setImageDrawable(getResources().getDrawable( R.drawable.sleeping_on));

sleeping_on 是一个图像,selector_sleeping_on 是一个选择器。 这是我的选择器:

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

<item android:drawable="@drawable/btn_sleeping_on" android:state_pressed="false"/>
<item android:drawable="@drawable/btn_sleeping" android:state_pressed="true"/> <!-- default -->

我只在“drawable-xhdpi”中有 sleeping_on 和 sleeping_off 图像。 为什么选择器显示的大小与普通 imageView 的大小不一样?我怎样才能使它们大小相同?

最佳答案

在您所说的这种情况下,One Thing 可以是其自身大小不同的图像,

您还可以做的一件事是您也可以修复选择器的大小。

以下是修复大小的代码段。

注意:您可以根据需要更改宽度和高度值。

<item>
 <shape android:shape="rectangle">
  <size android:width="30" android:height="40"/>
  <solid android:color="#000000" />
 </shape>
</item>

关于android - 选择器的大小与 "normal"图像不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13467746/

相关文章:

android - 无法实现可视化 :Geomap in android webview

android - 如何创建下拉列表?

java - 声明自定义 View 构造函数

android - 使用内置浏览器在 Samsung Messaging App 中进行深度链接

python - OLED 显示屏调整图像大小困难

python - 如何在Python中读取PGM图像

objective-c - 在 iOS 应用程序中获取和显示来自 Facebook 的图像

javascript - $ ("#id option").click(function(){ }) 不适用于 safari 或 chrome?

jQuery:选择器问题(最接近)

jquery - 如何选择具有特定 id 的父级的图像元素?