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 9000773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:21:07+00:00 2026-06-16T00:21:07+00:00

I want to change view height and width, (might be button view, image view,

  • 0

I want to change view height and width, (might be button view, image view, linearlayout, framelayout or any kind of view). I uses a method traverseRootViewAndSetLayoutParam(View,
double , double), to change do this. Its working if i commented these lines.

    if (view.getClass().equals(LinearLayout.class)) {
         LinearLayout.LayoutParams layoutParams = new
         LinearLayout.LayoutParams(
         (int) (((double) widthRatio) * (view.getWidth())),
         (int) (((double) heightRatio) * (view.getHeight())));
         view.setLayoutParams(layoutParams);
    } else if (view.getClass().equals(FrameLayout.class)) {
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
                (int) (((double) widthRatio) * (view.getWidth())),
                (int) (((double) heightRatio) * (view.getHeight())));
        view.setLayoutParams(layoutParams);
    }

, but if i run all the code than I am getting ClassCastException in onCreate() method,

I debug the code, the method traverseRootViewAndSetLayoutParam(View, double , double) is not giving the exception, but after control passes over the onCreate(), it gives the ClassCastException. I check it the control comes on line , System.outprintln(>> oncreate end >>). at this time i am not getting any error, but crossing the oncreate method exception occur.

the lines of code i am calling in onCreate method,

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
            ...
            ...
            ...
    try {
        traverseRootViewAndSetLayoutParam(rootLinearLayout, widthRatio,
                heightRatio);
    } catch (Exception e) {
        e.printStackTrace();
    }
System.out.println(">>> oncreate end >>> ");
   }

traverseRootViewAndSetLayoutParam() method,

public void traverseRootViewAndSetLayoutParam(View view,
        double heightRatio, double widthRatio) {

    System.out.println(">>> iCount >>> " + iCount++);

    if (view.getClass().equals(LinearLayout.class)) {
         LinearLayout.LayoutParams layoutParams = new
         LinearLayout.LayoutParams(
         (int) (((double) widthRatio) * (view.getWidth())),
         (int) (((double) heightRatio) * (view.getHeight())));
         view.setLayoutParams(layoutParams);
    } else if (view.getClass().equals(FrameLayout.class)) {
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
                (int) (((double) widthRatio) * (view.getWidth())),
                (int) (((double) heightRatio) * (view.getHeight())));
        view.setLayoutParams(layoutParams);
    }
    // else {
    // ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(
    // (int) (((double) widthRatio) * (view.getWidth())),
    // (int) (((double) heightRatio) * (view.getHeight())));
    // view.setLayoutParams(layoutParams);
    // }

    if (view instanceof LinearLayout || view instanceof FrameLayout) {
        if (view instanceof LinearLayout) {
            System.out.println(">>> LinearLayout Class >>> "
                    + view.getClass());
            int childcount = ((LinearLayout) view).getChildCount();
            for (int i = 0; i < childcount; i++) {
                View childView = ((LinearLayout) view).getChildAt(i);
                traverseRootViewAndSetLayoutParam(childView, heightRatio,
                        widthRatio);
            }
        } else if (view instanceof FrameLayout) {
            System.out.println(">>> FrameLayout Class >>> "
                    + view.getClass());
            int childcount = ((FrameLayout) view).getChildCount();
            for (int i = 0; i < childcount; i++) {
                View childView = ((FrameLayout) view).getChildAt(i);
                traverseRootViewAndSetLayoutParam(childView, heightRatio,
                        widthRatio);
            }
        }
    }
}

error log,

12-16 00:30:12.791: W/dalvikvm(277): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
12-16 00:30:12.952: E/AndroidRuntime(277): FATAL EXCEPTION: main
12-16 00:30:12.952: E/AndroidRuntime(277): java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:355)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.view.View.measure(View.java:8171)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:696)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:306)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.view.View.measure(View.java:8171)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.view.View.measure(View.java:8171)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.view.View.measure(View.java:8171)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.view.View.measure(View.java:8171)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.view.View.measure(View.java:8171)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.view.ViewRoot.performTraversals(ViewRoot.java:801)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.os.Looper.loop(Looper.java:123)
12-16 00:30:12.952: E/AndroidRuntime(277):  at android.app.ActivityThread.main(ActivityThread.java:4627)
12-16 00:30:12.952: E/AndroidRuntime(277):  at java.lang.reflect.Method.invokeNative(Native Method)
12-16 00:30:12.952: E/AndroidRuntime(277):  at java.lang.reflect.Method.invoke(Method.java:521)
12-16 00:30:12.952: E/AndroidRuntime(277):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-16 00:30:12.952: E/AndroidRuntime(277):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-16 00:30:12.952: E/AndroidRuntime(277):  at dalvik.system.NativeStart.main(Native Method)
12-16 00:30:42.751: I/Process(277): Sending signal. PID: 277 SIG: 9
  • 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-06-16T00:21:08+00:00Added an answer on June 16, 2026 at 12:21 am

    You’re getting this exception because the LayoutParams is always relative to the parent view group.

    e.g. you have a RelativeLayout and inside this RelativeLayout you have a LinearLayout, the LayoutParams of this LinearLayout will be a RelativeLayout.LayoutParams.

    That’s because those parameters are relative to how the parent layouts its views within its area.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to change an image on a view, from a popup dialog of
I want to change the height of a UIViewController's view that is inside a
I want to change the view size for iPhone 3.0, but I find that
i'm programming with opengl and i want to change the camera view: ... void
i want change the content of a UITableView when i change a button, how
I have a RadioButtnList. I want change body background color based on radio button
i have many div's with the same background image and i want change this
I want change following javascript code to jquery code, How is it? With done
What I want change the properties(e.g. background) of a context menu in a datatemplate
Hi, I had Generate custom layouts in my screen, i want change color or

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.