Android:如何防止图像在ImageView或ImageButton中缩放?

Android:如何防止图像在ImageView或ImageButton中缩放?,第1张

Android:如何防止图像在ImageView或ImageButton中缩放

我发现使用android:background时会自动将您正在使用的图像缩放到View的大小。

我尝试使用android:src将图像放在视图中。图像没有缩放,但是我无法使图像相对于View的大小居中。

因此,我尝试将整个Button设置为自己的相对布局,这就是我使用的方法:

<RelativeLayout android:id="@+id/RelativeLayout01"      android:layout_height="fill_parent"      android:layout_width="fill_parent">     <ImageButton android:id="@+id/ImageButton01"android:layout_height="fill_parent"       android:layout_width="fill_parent"></ImageButton>     <ImageView android:id="@+id/ImageView01"     android:layout_width="wrap_content"     android:layout_height="wrap_content"      android:background="@drawable/cardback1"      android:layout_centerInParent="true"></ImageView></RelativeLayout>

ImageButton在背景中,并且始终与布局相同。但是,ImageView将始终保持在RelativeLayout的中心,并且不会缩放。这样,RelativeLayout本身就可以增长和移动,并且按钮顶部的Image始终保持相同大小,但是按钮将增长。但是,如果布局小于图像本身,则图像将缩小。

我认为这就是您想要的。也许有更好的方法可以做到这一点,但这就是我现在能想到的。



欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/zaji/5623240.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存