Skip to content Skip to sidebar Skip to footer

Crash When Setting Parameter To Layout In Android

Expected Result Clicking on the toggle button will show up the menu and slide out the content view rightward. After animation is finished, the layout parameters of the content view

Solution 1:

mViewContent params should be added with resp to your Parent view, suppose you have parent view as LinearLayout then, LinearLayout.LayoutParams must be used.

Explaination:-

Take for example, LinearLayout.LayoutParams and RelativeLayout.LayoutParams, they are different independent classes. They store different additional information about child views... say..

  • LinearLayout.LayoutParams can associate weight value with each view, while RelativeLayout.LayoutParams can't.
  • RelativeLayout.LayoutParams can have values like alightWithParent,above, below with each view while LinearLayout.LayoutParams can't.

Although the code will not give compile time error because all LayoutParams have same parent class i.e. ViewGroup.LayoutParams. So, it is always essential, to assign Layout params with respect to parent layout..

Solution 2:

make sure you imported the correct layout params

import android.widget.LinearLayout.LayoutParams;

Post a Comment for "Crash When Setting Parameter To Layout In Android"