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

前端 未结 5 1053
清酒与你
清酒与你 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:10

    Above error due to passing wrong casting params :- because some time you set programattically parameter for linear layout but when you doing getLayoutParams() then it some time gives parent layout reference then it is gives above error .

    FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) parentLayout.getLayoutParams();
            int leftMargin = (int) getResources().getDimension(R.dimen.exclusion_card_margin_left_right);
            int rightMargin = (int) getResources().getDimension(R.dimen.exclusion_card_margin_left_right);
    
            params.setMargins(leftMargin, 0, rightMargin, 0);
            parentLayout.setLayoutParams(params);
    

提交回复
热议问题