public static void animateShowing( final ViewHolder holder, final ListAdapter adapter, boolean isAnimate) { final CheckBox checkBox = holder.checkBox; if (checkBox.getVisibility() == View.VISIBLE) { return; } checkBox.setVisibility(View.VISIBLE); checkBox.setAlpha(0.0f); final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); checkBox.measure(widthSpec, heightSpec); ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) checkBox.getLayoutParams(); final long transValue = checkBox.getMeasuredWidth() + lp.leftMargin + lp.rightMargin; if (!isAnimate) { checkBox.setAlpha(1.0f); holder.contentLayout.setTranslationX(transValue); return; } final ObjectAnimator transBodyAnimator = new ObjectAnimator(); final PropertyValuesHolder trans = PropertyValuesHolder.ofFloat("TranslationX", 0.0f, transValue); transBodyAnimator.setTarget(holder.contentLayout); transBodyAnimator.setValues(trans); transBodyAnimator.setDuration(DURATION); ObjectAnimator checkBoxAnim = new ObjectAnimator(); final PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("ScaleX", 0.0f, 1.0f); final PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("ScaleY", 0.0f, 1.0f); final PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("Alpha", 0.0f, 1.0f); checkBoxAnim.setValues(scaleX, scaleY, alpha); checkBoxAnim.setTarget(holder.checkBox); checkBoxAnim.setDuration(DURATION); checkBoxAnim.setInterpolator(new DecelerateInterpolator()); checkBoxAnim.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { checkBox.setTag("animating"); } @Override public void onAnimationEnd(Animator animation) { // adapter.setCheckBoxAnimator(false); checkBox.setTag("animated"); } }); if (!(checkBox.getTag() != null && "animating".equals(checkBox.getTag()))) { // 若正在播放动画,则不继续播放动画 transBodyAnimator.start(); checkBoxAnim.start(); } }
public static void animateHiding( final ViewHolder holder, final ListAdapter adapter, boolean isAnimate) { final CheckBox checkBox = holder.checkBox; final View tansBody = holder.contentLayout; if (checkBox.getVisibility() == View.GONE) { return; } ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) checkBox.getLayoutParams(); final float transValue = checkBox.getMeasuredWidth() + lp.leftMargin + lp.rightMargin; if (!isAnimate) { checkBox.setVisibility(View.GONE); holder.contentLayout.setTranslationX(0.0f); return; } final ObjectAnimator transBodyAnimator = new ObjectAnimator(); final PropertyValuesHolder trans = PropertyValuesHolder.ofFloat("TranslationX", transValue, 0.0f); transBodyAnimator.setTarget(tansBody); transBodyAnimator.setValues(trans); transBodyAnimator.setDuration(DURATION); ObjectAnimator checkBoxAnim = new ObjectAnimator(); final PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("ScaleX", 1.0f, 0.0f); final PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("ScaleY", 1.0f, 0.0f); final PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("Alpha", 1.0f, 0.0f); checkBoxAnim.setValues(scaleX, scaleY, alpha); checkBoxAnim.setTarget(checkBox); checkBoxAnim.setDuration(DURATION); checkBoxAnim.setInterpolator(new AccelerateInterpolator()); checkBoxAnim.addListener( new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { checkBox.setTag("animating"); } @Override public void onAnimationEnd(Animator animation) { // adapter.setCheckBoxAnimator(false); checkBox.setScaleX(1.0f); checkBox.setScaleY(1.0f); checkBox.setAlpha(1.0f); checkBox.setVisibility(View.GONE); checkBox.setTag("animated"); } }); if (!(checkBox.getTag() != null && "animating".equals(checkBox.getTag()))) { transBodyAnimator.start(); checkBoxAnim.start(); } }
private void addCheckbox(int i, int checkboxLayout, LayoutInflater li) { CheckBox view = (CheckBox) li.inflate(checkboxLayout, this, false); LayoutParams params = new TableRow.LayoutParams(0, view.getLayoutParams().height, 1f); if (i > 0) { params.setMargins(mPadding, 0, 0, 0); } view.setLayoutParams(params); view.setCompoundDrawablePadding(0); view.setTag(i); view.setText(String.valueOf(i + 1)); view.setOnCheckedChangeListener(this); addView(view); }
public void setMarginRightCheckBox(int marginRight) { LayoutParams params = (LayoutParams) checkOption.getLayoutParams(); params.rightMargin = marginRight; checkOption.setLayoutParams(params); }