安卓:经与拉伸/缩放上的图像按钮的问题 [英] Android: Having problems with stretching/scaling on an image button

查看:161
本文介绍了安卓:经与拉伸/缩放上的图像按钮的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在苦苦挣扎什么,我认为是简单的东西。我在使用类的图像按钮设置图像。我希望图像以适应屏幕的限制,但伸展。也就是说,如果它太宽以适应屏幕,我想要的高度进行调整,以适应这样它没有得到的拉伸的。而如果高度太高,我希望图像高度降低,从而也缩减宽度。

I have been struggling with what I think is something simple. I am setting an image on an image button using a class. I want the image to fit the constraints of the screen, but without stretching. That is, if it's too wide to fit the screen, I want the height to be scaled to accommodate so that it doesn't get stretched. And if the height is too tall, I want the image height to be reduced, thereby shrinking the width too.

我已经看到了这个问题问了几次,我都试过了咨询的每一位,但它使绝对没有什么区别我。我想,这可能是与usnig一个ImageButton的而不是ImageView的吗?

I have seen this question asked a couple times and I have tried every bit of the advice, but it makes absolutely no difference for me. I think this may have something to do with usnig an ImageButton instead of an ImageView?

下面是code(严重破)...

Here are some relevant chunks of code (badly broken) ...

在我的类:

          ImageView img = (ImageButton) dialog.findViewById(R.id.fullsizeimage);
          img.setScaleType(ImageView.ScaleType.CENTER_INSIDE);  //Changing ScaleType here has no effect
          img.setImageBitmap(useThisBitmap);

和这里的XML布局的内容...

And here is the xml layout contents ...

 <?xml version="1.0" encoding="utf-8"?>
   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

<ImageButton
    android:id="@+id/fullsizeimage"
    android:background="@null"
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent"
    android:adjustViewBounds="true"
    />

 </RelativeLayout>

有的在XML文件中的垃圾很可能是错误的。但我已经改变了很多次,而且它具有零效果。

Some of that junk in the XML file is probably wrong. But I have changed it so many times, and it has ZERO effect.

任何和所有的建议是的极大地的AP preciated。

Any and all advise is greatly appreciated.

推荐答案

我觉得会的ImageButton伸展始终背景图像,以填补其整个背景。
一个ImageView的可以轻松完成自身的点击,你试过了吗?

I think that ImageButton will always stretch the background image in order to fill its whole background. An ImageView can be easily made clickable on its own, have you tried that?

一个更复杂的方法是使用它可以在画布上绘制图像,你喜欢的任何方式,可以有onTouch监听器自定义视图。

A more complicated option is to use a custom view which can draw your image on canvas any way you like and can have onTouch listener.

这篇关于安卓:经与拉伸/缩放上的图像按钮的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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