LinearLayout$LayoutParams cannot be cast to android.widget.FrameLayout$LayoutParams

前端 未结 5 1116
清酒与你
清酒与你 2021-02-01 12:46

Explanation and solution at the bottom.

I am developing one slider layout animation, the animation work fine but when all processes end, they get next E

5条回答
  •  误落风尘
    2021-02-01 13:07

    You should not make the LayoutParmas object of the layout whose dimension you want to set from java. Rather you should make the LayoutParams object of the parent layout. For example in the layout below to set the layout params of the LinearLayout you have to make the LayoutParmas of RelativeLayout not LinearLayout itself:

    
    
    
        
    
    
    

    In activity class:

    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(30,30); // parent params
    linearLayout.setLayoutParmas(params); // child layout
    

    If you want to set the params of the RelativeLayout, it seems it doesn't have any parent but it has a parent created by android framework which is a frame layout:

    FrameLayout.LayoutParmas params = new FrameLayout.LayoutParmas(30, 30); // FrameLayout is a parent-created by android framework
    relativeLayout.setLayoutParmas(params); // relative layout is child here
    

提交回复
热议问题