Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7009677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:53:34+00:00 2026-05-27T21:53:34+00:00

Take the following code: ImageView imageView = new ImageView(activity); imageView.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); Running this

  • 0

Take the following code:

ImageView imageView = new ImageView(activity);
imageView.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

Running this crashes my app. I can’t for the life of me work out how to set the height/weight of an ImageView created in code.

01-05 14:46:34.593: E/AndroidRuntime(12038): FATAL EXCEPTION: main
01-05 14:46:34.593: E/AndroidRuntime(12038): java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
01-05 14:46:34.593: E/AndroidRuntime(12038):    at android.widget.Gallery.setUpChild(Gallery.java:772)
01-05 14:46:34.593: E/AndroidRuntime(12038):    at android.widget.Gallery.makeAndAddView(Gallery.java:741)
01-05 14:46:34.593: E/AndroidRuntime(12038):    at android.widget.Gallery.layout(Gallery.java:625)
01-05 14:46:34.593: E/AndroidRuntime(12038):    at android.widget.Gallery.onLayout(Gallery.java:339)
01-05 14:46:34.593: E/AndroidRuntime(12038):    at android.view.View.layout(View.java:7175)
01-05 14:46:34.593: E/AndroidRuntime(12038):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
01-05 14:46:34.593: E/AndroidRuntime(12038):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
01-05 14:46:34.593: E/AndroidRuntime(12038):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
01-05 14:46:34.593: E/AndroidRuntime(12038):    at android.view.View.layout(View.java:7175)
01-05 14:46:34.593: E/AndroidRuntime(12038):    at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
01-05 14:46:34.593: E/AndroidRuntime(12038):    at android.widget.ScrollView.onLayout(ScrollView.java:1296)
01-05 14:46:34.593: E/AndroidRuntime(12038):    at android.view.View.layout(View.java:7175)
01-05 14:46:34.593: E/AndroidRuntime(12038):    at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
01-05 14:46:34.593: E/AndroidRuntime(12038):    at android.view.View.layout(View.java:7175)
01-05 14:46:34.593: E/AndroidRuntime(12038):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
01-05 14:46:34.593: E/AndroidRuntime(12038):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
01-05 14:46:34.593: E/AndroidRuntime(12038):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
01-05 14:46:34.593: E/AndroidRuntime(12038):    at android.view.View.layout(View.java:7175)
01-05 14:46:34.593: E/AndroidRuntime(12038):    at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
01-05 14:46:34.593: E/AndroidRuntime(12038):    at android.view.View.layout(View.java:7175)
01-05 14:46:34.593: E/AndroidRuntime(12038):    at android.view.ViewRoot.performTraversals(ViewRoot.java:1140)
01-05 14:46:34.593: E/AndroidRuntime(12038):    at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
01-05 14:46:34.593: E/AndroidRuntime(12038):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-05 14:46:34.593: E/AndroidRuntime(12038):    at android.os.Looper.loop(Looper.java:130)
01-05 14:46:34.593: E/AndroidRuntime(12038):    at android.app.ActivityThread.main(ActivityThread.java:3683)
01-05 14:46:34.593: E/AndroidRuntime(12038):    at java.lang.reflect.Method.invokeNative(Native Method)
01-05 14:46:34.593: E/AndroidRuntime(12038):    at java.lang.reflect.Method.invoke(Method.java:507)
01-05 14:46:34.593: E/AndroidRuntime(12038):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-05 14:46:34.593: E/AndroidRuntime(12038):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-05 14:46:34.593: E/AndroidRuntime(12038):    at dalvik.system.NativeStart.main(Native Method)

For the record the image view I’m creating is created within the getView method of the BaseAdapter class which is then used by a Gallery.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:53:34+00:00Added an answer on May 27, 2026 at 9:53 pm

    I think you have ImageView in LinearLayout but you are passing LayoutParams for RelativeLayout. Please try this.

    ImageView imageView = new ImageView(activity);
    imageView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Take the following code: <abbr title=World Health Organization>WHO</abbr> Can we style an abbr tag's
Take the Following code: DESCryptoServiceProvider des = new DESCryptoServiceProvider(); des.Key = new byte[] {
Take this following code from an example HR system. The user has the ability
Take a gander at the following code. Basically, this is a function that gets
Is there a way around this issue? Take the following code... namespace ReflectionResearch {
Take the following code: var first = new Date(2011-09-17T15:12:04.331Z); var second = new Date(2011-09-17T19:55:19.269Z);
Take the following code: std::vector<std::vector<int>> v(10, 10); This code doesn't compile with libstdc++. It
Take the following code for example; if (Convert.ToString(frm.WindowState) == Minimized) Layout.WindowState = Maximized; else
Take the following code snippet: SPAttachmentCollection attachments = item.Attachments ; What exactly is SPAttachmentCollection
Take the following code: public static string ReverseIt(string myString) { char[] foo = myString.ToCharArray();

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.