params = (); marginParams = null; //获取view的margin设置参数 if (params instanceof ) { marginParams = () params; } else { //不存在时创建一个新的参数 //基于View本身原有的布局参数对象 marginParams = new (params); } (0,0,1,0);
千万记住这里面的if 语句的判断, 如果直接marginParams = new (params); 会报错
-
E/AndroidRuntime: FATAL EXCEPTION: main
-
Process: , PID: 14673
-
: $MarginLayoutParams cannot be cast to $LayoutParams
-
at (:779)
-
at (:685)
-
at (:22093)
-
at (:6614)
-
at (:1514)
-
at (:806)
-
at (:685)
-
at (:22093)
-
at (:6614)