Android.widget.framelayout$layoutparams cannot is cast to Android.widget.linearlayout$layoutparams

Source: Internet
Author: User

http://blog.csdn.net/lilu_leo/article/details/11952717

Sometimes you need to set layoutparams in the code, you set the Layoutparams for a framelayout, encounter title problems,

Java.lang.ClassCastException:android.widget.FrameLayout$LayoutParams cannot is cast to Android.widget.LinearLayout$LayoutParams 

Framelayout's parent control is a LinearLayout control, and the problem is that when LinearLayout allocates space for a child control, The layoutparams of the framelayout must be linearlayout.layoutparams, not framelayout.layoutparams.

Simply give a chestnut to illustrate: the outermost has relativelayout a, which has two linearlayout B, C, and B has a framelayout D. If you want to set B's layoutparams,b in the code, Layoutparams is relativelayout.layoutparams.

New Relativelayout.layoutparams (Layoutparams.match_parent, layoutparams.match_parent);     b.setlayoutparams (params); 

and d to set it, you need:
0);      8;  D.setlayoutparams (params);  

This problem can be solved. Or some of their basic knowledge is not strong, write this.

Android.widget.framelayout$layoutparams cannot is cast to Android.widget.linearlayout$layoutparams

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.