无论我尝试什么,我都无法设置从soap服务传递到我的
android模拟器的图像的宽度和高度.我正在使用
ImageView,如下所示:
byte[] bloc = Base64.decode(result,Base64.DEFAULT); Bitmap bmp = BitmapFactory.decodeByteArray(bloc,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);
在上面的代码中,我试图手动设置宽度为259像素,高度为194像素的jpeg图像的宽度和高度.
/res/layout/main.xml看起来像
<?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>
在尝试下面的答案中的一些方法后,我只是在我的模拟器上看到以下内容
我甚至不确定我采取的方法是否正确.我在搜索论坛时找到的大多数其他解决方案对我不起作用.任何建议都会很棒.
解决方法
试试这样吧.使用yourBitmap.getWidth()和.getHeight()
image.setLayoutParams( new LinearLayout.LayoutParams( bmp.getWidth(),bmp.getHeight()));
编辑:
现在您已经为ImgView设置了LP,您要做的第一件事就是将它添加到布局中
LinearLayout ll =(LinearLayout)findViewById(R.layout.llid);
现在你可以直接添加视图,也可以像分离参数一样添加.addView(view,params)或.addView(View);你的来电.
所以你也是
ll.addView(图像);
希望它有效
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。