Android: with RippleEffect & StateListAnimator

前端 未结 2 1267
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-19 08:37

I have a layout, that includes another layout:



        
2条回答
  •  长发绾君心
    2021-02-19 09:17

    You need to find the view and call the appropriate method to change the state list animator and the background. You might need to also call setClickable on the root view of you included layout.

    LinearLayout layout1 = findViewById(R.id.layout1);
    View root = layout1.getChildAt(0);
    
    StateListAnimator sla = AnimatorInflater.loadStateListAnimator(context, R.anim.lift_up); 
    root.setStateListAnimator(sla);
    root.setBackground(R.drawable.ripple_effect);
    

提交回复
热议问题