我正在使用 PropertyValuesHolder 为我的 Android 应用程序中的一些视图设置动画。动画在我的设备上运行良好,直到我在没有任何动画的地方进行发布构建。(我认为问题与混淆有关,因为属性名称被称为字符串名称,例如“Panel1W”)
没有抛出异常。只是没有动画。我在http://proguard.sourceforge.net/index.html#manual/troubleshooting.html上能找到的最接近的东西 是 NoSuchMethodException,我们需要在 proguard.cfg 中使用 -keep 命令。我在我的 proguard.cfg 中尝试了以下但没有成功
-keep public class com.mycompany.myapp.HomeActivity { java.lang.Integer getPanel1W(); }
-keep public class com.mycompany.myapp.HomeActivity { void setPanel1W(java.lang.Integer); }
-keep public class com.mycompany.myapp.HomeActivity { java.lang.Integer getPanel2W(); }
-keep public class com.mycompany.myapp.HomeActivity { void setPanel2W(java.lang.Integer); }
-keep public class com.mycompany.myapp.HomeActivity { java.lang.Integer getPanel3W(); }
-keep public class com.mycompany.myapp.HomeActivity { void setPanel3W(java.lang.Integer); }
我错过了什么吗?这是下面的代码。谢谢。
PropertyValuesHolder[] arrayOfPropertyValuesHolder = new PropertyValuesHolder[3];
arrayOfPropertyValuesHolder[0] = PropertyValuesHolder.ofInt("Panel1W", mPanel1.getWidth(), 0);
arrayOfPropertyValuesHolder[1] = PropertyValuesHolder.ofInt("Panel2W", 360, 1280);
arrayOfPropertyValuesHolder[2] = PropertyValuesHolder.ofInt("Panel3W", 0, (int)(screenWidth * 0.65));
ObjectAnimator localObjectAnimator = ObjectAnimator.ofPropertyValuesHolder(this,
arrayOfPropertyValuesHolder).setDuration(time);
localObjectAnimator.setInterpolator(sCollapseInterpolator);
localObjectAnimator.start();
我也有 getter 和 setter 方法。
public int getPanel1W() {
return ((ViewGroup.MarginLayoutParams) mPanel1.getLayoutParams()).width;
}
public void setPanel1W(int paramInt) {
ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mPanel1.getLayoutParams();
lp.width = paramInt;
mPanel1.setLayoutParams(lp);
}
public int getPanel2W() {
return ((ViewGroup.MarginLayoutParams) mPanel2.getLayoutParams()).width;
}
public void setPanel2W(int paramInt) {
ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mPanel2.getLayoutParams();
lp.width = paramInt;
mPanel2.setLayoutParams(lp);
}
public int getPanel3W() {
return ((ViewGroup.MarginLayoutParams) mPanel3.getLayoutParams()).width;
}
public void setPanel3W(int paramInt) {
ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mPanel3.getLayoutParams();
lp.width = paramInt;
mPanel3.setLayoutParams(lp);
}