问题描述
无论我怎么努力,我不能把我的是从一个SOAP服务传递给我的Android模拟器图像的宽度和高度。我使用的ImageView如下:
No matter what I try, I cannot set the width and height of my image that is passed from a soap service to my android emulator. I'm using an ImageView as follows:
byte[] bloc = Base64.decode(result, Base64.DEFAULT);
Bitmap bmp = BitmapFactory.decodeByteArray(bloc,0,bloc.length);
ImageView image = new ImageView(this);
image.setImageBitmap(bmp);
image.setLayoutParams(
new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
image.getLayoutParams().height = 100;
image.getLayoutParams().width = 100;
setContentView(image);
在上面的code,我试图手动设置,有一个259px宽194px高度JPEG图像的宽度和高度。
In the above code, I am attempting to set the width and height manually, of a jpeg image that has a 259px width and 194px height.
在/res/layout/main.xml看起来像
The /res/layout/main.xml looks like
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1" android:id="@+id/llid">
</LinearLayout>
在尝试一些下面的答案办法,我只是看到我的模拟器以下
After trying some of the approaches in below's answers, I just see the following on my emulator
我甚至不知道如果我采取的做法是正确的。大多数其他的解决方案,我发现从搜索论坛不为我工作。任何建议将是巨大的。
I'm not even sure if the approach I am taking is correct. Most other solutions I have found from searching the forums don't work for me. Any suggestions would be great.
推荐答案
试试这样。做一个使用 yourBitmap.getWidth()
和 .getHeight()
Try like this. Make a use of yourBitmap.getWidth()
and .getHeight()
image.setLayoutParams(
new LinearLayout.LayoutParams(
bmp.getWidth(),
bmp.getHeight()));
编辑:
现在您已设置了LP的ImgView,你必须做的第一件事就是将它添加到布局
Now you have set the LP for the ImgView, the first thing you have to do is to add it to the layout
的LinearLayout LL =(的LinearLayout)findViewById(R.layout.llid);
现在你可以直接增加你的观点,或者你可以像分离的参数和 .addView(视图,则params)
或 .addView(查看); 您的通话
Now you can either add your view straight or you can do it like separating the parameters and adding it with .addView(view, params)
or .addView(View);
Your call.
让你做
ll.addView(图像);
希望工程
这篇关于设置图片的宽度和高度的ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!