How to programmaticaly resize an Image programmatically

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

How to programmaticaly resize an Image programmatically

Postby madsurfer » Mon Jun 15, 2009 10:01 pm

Hi all,

I stuck on resizing an imageview using the setLayoutParams().

The parent of my ImageView is a HorizontalScrollView. And depending on the size of a picture, I need to resize my ImageView.

I tried like this, but allways get an exception:

ImageView _iv = (ImageView) findViewById(R.id.ivStrip);
LayoutParams _lp = new LayoutParams(1226, 640);
_iv.setLayoutParams(_lp);
_iv.setImageResource(R.drawable.MyPic);

Exception:
06-15 19:56:37.773: ERROR/AndroidRuntime(1163): java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
06-15 19:56:37.773: ERROR/AndroidRuntime(1163): at android.widget.FrameLayout.onLayout(FrameLayout.java:288)
06-15 19:56:37.773: ERROR/AndroidRuntime(1163): at android.widget.HorizontalScrollView.onLayout(HorizontalScrollView.java:1098)
06-15 19:56:37.773: ERROR/AndroidRuntime(1163): at android.view.View.layout(View.java:6133)
06-15 19:56:37.773: ERROR/AndroidRuntime(1163): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119)
06-15 19:56:37.773: ERROR/AndroidRuntime(1163): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:998)
06-15 19:56:37.773: ERROR/AndroidRuntime(1163): at android.widget.LinearLayout.onLayout(LinearLayout.java:918)
06-15 19:56:37.773: ERROR/AndroidRuntime(1163): at android.view.View.layout(View.java:6133)
06-15 19:56:37.773: ERROR/AndroidRuntime(1163): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
06-15 19:56:37.773: ERROR/AndroidRuntime(1163): at android.view.View.layout(View.java:6133)
06-15 19:56:37.773: ERROR/AndroidRuntime(1163): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119)
06-15 19:56:37.773: ERROR/AndroidRuntime(1163): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:998)
06-15 19:56:37.773: ERROR/AndroidRuntime(1163): at android.widget.LinearLayout.onLayout(LinearLayout.java:918)
06-15 19:56:37.773: ERROR/AndroidRuntime(1163): at android.view.View.layout(View.java:6133)
06-15 19:56:37.773: ERROR/AndroidRuntime(1163): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
06-15 19:56:37.773: ERROR/AndroidRuntime(1163): at android.view.View.layout(View.java:6133)
06-15 19:56:37.773: ERROR/AndroidRuntime(1163): at android.view.ViewRoot.performTraversals(ViewRoot.java:929)
06-15 19:56:37.773: ERROR/AndroidRuntime(1163): at android.view.ViewRoot.handleMessage(ViewRoot.java:1482)
06-15 19:56:37.773: ERROR/AndroidRuntime(1163): at android.os.Handler.dispatchMessage(Handler.java:99)
06-15 19:56:37.773: ERROR/AndroidRuntime(1163): at android.os.Looper.loop(Looper.java:123)
06-15 19:56:37.773: ERROR/AndroidRuntime(1163): at android.app.ActivityThread.main(ActivityThread.java:3948)
06-15 19:56:37.773: ERROR/AndroidRuntime(1163): at java.lang.reflect.Method.invokeNative(Native Method)
06-15 19:56:37.773: ERROR/AndroidRuntime(1163): at java.lang.reflect.Method.invoke(Method.java:521)
06-15 19:56:37.773: ERROR/AndroidRuntime(1163): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
06-15 19:56:37.773: ERROR/AndroidRuntime(1163): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
06-15 19:56:37.773: ERROR/AndroidRuntime(1163): at dalvik.system.NativeStart.main(Native Method)


MadSurfer
madsurfer
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Jun 15, 2009 9:53 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 2 guests