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.LayoutParamscan associate weight value with each view, whileRelativeLayout.LayoutParamscan't.RelativeLayout.LayoutParamscan have values likealightWithParent,above,belowwith each view whileLinearLayout.LayoutParamscan'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"