android - Programatcally remove margin from FrameLayout with LayoutParams -
i have framelayout looks this:
<relativelayout android:layout_width="match_parent" android:layout_height="wrap_content"> <framelayout android:layout_margintop="56dp" android:layout_marginbottom="50dp" android:id="@+id/main_frag" android:layout_width="match_parent" android:layout_height="match_parent" /> // other stuff </relativelayout>
however when change margins programitcally classcastexception.
framelayout fl = (framelayout) findviewbyid(r.id.main_frag); framelayout.layoutparams params = (framelayout.layoutparams) fl.getlayoutparams(); params.setmargins(50, 0, 0, 0); fl.setlayoutparams(params);
here how trying:
framelayout fl = (framelayout) findviewbyid(r.id.main_frag); framelayout.layoutparams params = (framelayout.layoutparams) fl.getlayoutparams(); params.setmargins(50, 0, 0, 0); fl.setlayoutparams(params);
here logcat
:
04-25 16:18:08.385: e/androidruntime(27682): java.lang.runtimeexception: unable start activity componentinfo{com.---.---/com.------.---.mainfragmentactivity}: java.lang.classcastexception: android.widget.relativelayout$layoutparams cannot cast android.widget.framelayout$layoutparams 04-25 16:18:08.385: e/androidruntime(27682): @ android.app.activitythread.performlaunchactivity(activitythread.java:2314) 04-25 16:18:08.385: e/androidruntime(27682): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2388) 04-25 16:18:08.385: e/androidruntime(27682): @ android.app.activitythread.access$800(activitythread.java:148) 04-25 16:18:08.385: e/androidruntime(27682): @ android.app.activitythread$h.handlemessage(activitythread.java:1292) 04-25 16:18:08.385: e/androidruntime(27682): @ android.os.handler.dispatchmessage(handler.java:102) 04-25 16:18:08.385: e/androidruntime(27682): @ android.os.looper.loop(looper.java:135) 04-25 16:18:08.385: e/androidruntime(27682): @ android.app.activitythread.main(activitythread.java:5312) 04-25 16:18:08.385: e/androidruntime(27682): @ java.lang.reflect.method.invoke(native method) 04-25 16:18:08.385: e/androidruntime(27682): @ java.lang.reflect.method.invoke(method.java:372) 04-25 16:18:08.385: e/androidruntime(27682): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:901) 04-25 16:18:08.385: e/androidruntime(27682): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:696) 04-25 16:18:08.385: e/androidruntime(27682): caused by: java.lang.classcastexception: android.widget.relativelayout$layoutparams cannot cast android.widget.framelayout$layoutparams 04-25 16:18:08.385: e/androidruntime(27682): @ com.---.---.mainfragmentactivity.oncreate(mainfragmentactivity.java:81) 04-25 16:18:08.385: e/androidruntime(27682): @ android.app.activity.performcreate(activity.java:5953) 04-25 16:18:08.385: e/androidruntime(27682): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1128) 04-25 16:18:08.385: e/androidruntime(27682): @ android.app.activitythread.performlaunchactivity(activitythread.java:2267)
i don't understand how relativelayout
involved here?
the layoutparams
class dictated parent, not child. layoutparams
affect framelayout
relativelayout.layoutparams
. layoutparams
affects child of framelayout
framelayout.layoutparams
.
Comments
Post a Comment