LayerDrawable一起改变

时间:2017-02-03 16:14:23

标签: android animation drawable layerdrawable

我有一个神奇的问题。 LayerDrawable的所有实例一起更改。 我有几个典型的观点。所以为了完成我的任务,我决定“我将被使用”复合视图“。我遇到了一个问题:
 当我更改一个图层可绘制的可见性时<所有的变化。

public abstract class BaseContentExpanded<DATA> extends FrameLayout implements ExpandableLayout.AdditionalAnimators {

 // same not imprtand code

 @Override
public List<? extends Animator> getAnimators(final boolean togle) {

    final Drawable showDrawable;
    final Drawable hideDraawable;
    final LayerDrawable layerDrawable = (LayerDrawable) vStateSelectionIcon.getDrawable();


    if (togle) {
        showDrawable = layerDrawable.getDrawable(0);
        hideDraawable = layerDrawable.getDrawable(isCanExpand ? 1 : 2);
    } else {
        hideDraawable = layerDrawable.getDrawable(0);
        showDrawable = layerDrawable.getDrawable(isCanExpand ? 1 : 2);
    }


    ValueAnimator expandAnimator = ValueAnimator.ofFloat(0f, 1f);
    expandAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            Log.d(TAG, "getAnimators: " + layerDrawable);
            float currentExpandAnimationValue = (float) animation.getAnimatedValue();
            showDrawable.setAlpha((int) (255 * currentExpandAnimationValue));
            hideDraawable.setAlpha((int) (255 * (1 - currentExpandAnimationValue)));
        }
    });


    return Arrays.asList(expandAnimator);
}

}

和LayerDrawable的xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
	<item>
		<bitmap android:src="@drawable/ic_close_light"/>
	</item>


	<item
		android:drawable="@drawable/vector_ic_arrow_down_blue_stroke_24dp"/>

	<item
		android:drawable="@drawable/vector_ic_arrow_right_blue_24dp"/>


</layer-list>

布局

        <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="@drawable/line_divider"
        android:orientation="vertical"
        android:showDividers="middle"
        >

        <com.learnx.android.ui.view.filters.LocationFilter
            android:id="@+id/location"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            />

        <com.learnx.android.ui.view.filters.RatingFilter
            android:id="@+id/rating"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            />
    </LinearLayout>

我将不胜感激任何帮助。

1 个答案:

答案 0 :(得分:0)

我弄错了。我忘记了调用mutate();

final LayerDrawable layerDrawable = (LayerDrawable) vStateSelectionIcon.getDrawable();
    LayerDrawable copyDrawable = (LayerDrawable) layerDrawable.mutate();