Android的:如何prevent图像被缩放的ImageView或ImageButton的? [英] Android: How to prevent image from being scaled in ImageView or ImageButton?

查看:113
本文介绍了Android的:如何prevent图像被缩放的ImageView或ImageButton的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能prevent我的位图被中的ImageView或ImageButton的自动缩放如果视图或按钮,使用FILL_PARENT或者使用权重被拉长?

How can I prevent my bitmap from being scaled automatically in an ImageView or ImageButton if the view or button is stretched using "fill_parent" or using "weight"?

这将是有用的,例如,以在屏幕的顶部,其中按钮被等距创建4按钮栏,但内部的按钮图像继续得到streched即使我使用scaleType =中心,应根据该文档prevent缩放,但是事实并非如此。

This will be useful, for example, to create a 4-button toolbar at the top of the screen where the buttons are equally spaced, but the images inside the buttons keep getting streched even if I use scaleType="center", which should prevent scaling according to the doc, but it doesn't.

任何有识之士的AP preciated!

Any insight is appreciated!

谢谢

推荐答案

我还发现,使用机器人时:后台自动缩放您使用那里的查看大小的图片

I have found that when using android:background automatically scales the image you are using there to the size of the View.

我试着使用了android:SRC把图像中的视图。图像没有形成规模,但我不能让图像居中相对于视图的大小。

I tried using the android:src to put the image in the view. The image did not scale, but I could not get the image to center relative to the size of the View.

所以,我试图使整个按钮,它自身的相对布局,这是我使用的是什么:

So I tried making the whole Button it's own relative layout and this is what I used:

<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的自身成长和移动和按钮上方的形象将永远留相同的大小,但按钮将增长。如果布局变得比图像本身更小的图像但萎缩。

The ImageButton is in the background and will always be the same size as the layout. The ImageView however will always stay centered in the RelativeLayout and will not scale. This way the RelativeLayout itself can grow and move and the Image on top of the button will always stay the same size, but the button will grow. The image will however shrink if the Layout becomes smaller than the image itself.

我想这就是你要找的人。有可能是一个更好的方式来做到这一点,但是这是我能想出现在。

I think that's what you were looking for. There may be a better way to do this, but this is all I can come up with right now.

这篇关于Android的:如何prevent图像被缩放的ImageView或ImageButton的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆