图层可绘制一起更改



我有一个神奇的问题。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);
}

}

和 xml 表示 LayerDrawable

<?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>

我将不胜感激任何帮助。

我伤了错误。 我忘记调用突变();

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

相关内容

  • 没有找到相关文章

最新更新