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

  • Home
  • SEARCH
  • 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 8989535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:17:05+00:00 2026-06-15T22:17:05+00:00

I have a RelativeLayout with the xml something like: <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android

  • 0

I have a RelativeLayout with the xml something like:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/appHolder"
  android:layout_width="210dp"
  android:layout_height="100dp"
  android:background="@drawable/app_container_box"
  android:paddingBottom="10dp"
  android:paddingLeft="15dp"
  android:paddingRight="10dp"
  android:paddingTop="10dp" >
  ...
</RelativeLayout>

I want to programmatically modify the width of this layout based on some condition.

In the GetView() method, I have:

public View getView(int position, View recycledView, ViewGroup viewGroup) {
    View row = recycledView;
    Holder holder;
    row = inflater.inflate(R.layout.app_icon_tile, viewGroup, false);
    if (row == null) {
        /*
        * I added only the following `if` block
        * The rest is older code and was working fine
        */
        if (changeWidth) {
            row.setLayoutParams(new RelativeLayout.LayoutParams(260, 100));
        }
        holder = new Holder();
        holder.icon = (ImageView) row.findViewById(R.id.gridAppIcon);
        holder.appTitle = (TextView) row.findViewById(R.id.gridAppTitle);
        row.setTag(holder);
    } else {
        holder = (Holder) row.getTag();
    }
    return (row);
}

But when running this code, my application crashes with the following stack trace:

FATAL EXCEPTION: main
java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams
       at android.widget.GridView.onMeasure(GridView.java:937)
       at android.view.View.measure(View.java:8314)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
       at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
       at android.widget.LinearLayout.measureVertical(LinearLayout.java:386)
       at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
       at android.view.View.measure(View.java:8314)
       at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:581)
       at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:365)
       at android.view.View.measure(View.java:8314)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
       at android.view.View.measure(View.java:8314)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
       at android.view.View.measure(View.java:8314)
       at android.view.ViewRoot.performTraversals(ViewRoot.java:843)
       at android.view.ViewRoot.handleMessage(ViewRoot.java:1866)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:130)
       at android.app.ActivityThread.main(ActivityThread.java:3683)
       at java.lang.reflect.Method.invokeNative(Native Method)
       at java.lang.reflect.Method.invoke(Method.java:507)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:638)
       at dalvik.system.NativeStart.main(Native Method)

What am I missing?

  • 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-15T22:17:06+00:00Added an answer on June 15, 2026 at 10:17 pm

    Your problem lies here:

    if (changeWidth) {
           row.setLayoutParams(new RelativeLayout.LayoutParams(260, 100));
    }
    

    Because when you set layout params, they should be of parent’s type, not the view’s for which you’re creating params itself.

    So for example if your RelativeLayout is in a ListView, it should get ListView.LayoutParams.

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

Sidebar

Related Questions

So, I have this layout: <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/layout android:layout_width=fill_parent android:layout_height=wrap_content android:background=#FFFF00
I have this code: <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent android:orientation=vertical android:gravity=top android:background=@drawable/db_bg_color>
I have the following layout: <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent> <GridView android:id=@+id/grid
So I have two files: where_include_happens.xml <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/hours android:layout_height=wrap_content android:layout_width=60dp>
I am trying to inflate <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=wrap_content> <Item android:id=@+id/ltArr
In my foo_layout.xml file I have a subclassed RelativeLayout: <?xml version=1.0 encoding=utf-8?> <FrameLayout xmlns:android=http://schemas.android.com/apk/res/android
I have a rather simple ListView row: <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=wrap_content
I currently have an xml layout called quests.xml: <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent
On one fragment I have layout like question.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView
I have the following XML file <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android xmlns:tools=http://schemas.android.com/tools android:layout_width=match_parent android:layout_height=match_parent android:background=@drawable/welcome_bg > <FrameLayout

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.