gpt4 book ai didi

Android ImageButton 按比例缩小

转载 作者:搜寻专家 更新时间:2023-11-01 08:50:36 25 4
gpt4 key购买 nike

我想在我的布局中添加一个 ImageButton,它具有按比例缩小的效果,以便看起来像是被按下了。所以我基本上有原始图像 @drawable/scan 和压缩图像 @drawable/scanhot。 Scanhot 基本上是按比例缩小 的相同图像。

我的代码如下,但它似乎不起作用。

如您所见,我使用的是 Button 而不是 ImageButton,因为 Button 至少可以“切换”不同的图像。但是它对类似的图像没有任何作用,例如扫描/扫描

button_rescan.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/scanhot"/>
<item
android:drawable="@drawable/scan"/>
</selector>

布局

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp"
android:background="@android:color/transparent">

<Button
android:id="@+id/fragment_radar_rescan_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_rescan"
android:layout_gravity="center_horizontal"
android:layout_centerHorizontal="true"/>
</RelativeLayout

最佳答案

看起来 drawable/scanhot 的大小 drawable/scan 不一样(以像素为单位)。因此,如果您想要“缩放”(或其他)效果,您仍然应该保持两张图像的图像大小相同(即 100x100),并且使用相同的大小使 scanhot 看起来更小。如果您已经根据需要缩放图像,只需将较小的图像加载到 Gimp 或 Photoshop 并将其 canvas 缩放到另一幅图像的大小(我假设更大),然后保存。在这种情况下,两者的 Canvas 将是相同的,并且您可以避免从 ImageView 进行额外的缩放

关于Android ImageButton 按比例缩小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23836323/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com