我编写了一个小代理类,以便我可以使用ObjectAnimator为视图的边距设置动画.在检查这是否有效以及所有动画都正确动画之后,我想在动画之前调整视图的大小,但在设置宽度后,我的动画因ClassCastException而失败.我不知道为什么.
private class handleClickListener implements View.OnClickListener {
private static final int LEFT_MARGIN_VISIBLE = 0;
private static final int LEFT_MARGIN_HIDDEN = -196;
public void onClick(View view) {
LinearLayout row = (LinearLayout) view.getParent().getParent();
RelativeLayout options = (RelativeLayout) row.findViewById(R.id.options);
LayoutProxy layoutProxy = new LayoutProxy(options);
// First make sure the options are the right width to fill the screen with the handle
int rowWidth = row.getWidth();
int handleWidth = view.getWidth();
layoutProxy.setWidth(rowWidth - handleWidth);
ObjectAnimator animation;
if (layoutProxy.getLeftMargin() == Util.dipsToPixels(options, LEFT_MARGIN_VISIBLE)) {
animation = ObjectAnimator.ofInt(layoutProxy, …Run Code Online (Sandbox Code Playgroud)