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);
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.
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.
Try like this. Make a use of yourBitmap.getWidth()
and .getHeight()
image.setLayoutParams(
new LinearLayout.LayoutParams(
bmp.getWidth(),
bmp.getHeight()));
Edit:
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);
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.
so you do
ll.addView(image);
Hope it works
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With