1

I have a magic problem. All instance of LayerDrawable change together. I have several typical Views. So to done my task i decide "I will be used "Composite view". I got a problem:
When i change visibility on one Layer drawable< the change on all.

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);
}

}

And xml for 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>

Layout

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

I will be grateful for any help.

Rod_Algonquin
  • 26,074
  • 6
  • 52
  • 63
Vitaliy Ptitsin
  • 329
  • 1
  • 5
  • 14

1 Answers1

2

I wound the mistake. i forget call mutate();

final LayerDrawable layerDrawable = (LayerDrawable) vStateSelectionIcon.getDrawable();
    LayerDrawable copyDrawable = (LayerDrawable) layerDrawable.mutate();
Vitaliy Ptitsin
  • 329
  • 1
  • 5
  • 14