gpt4 book ai didi

Android: 与 RippleEffect & StateListAnimator

转载 作者:可可西里 更新时间:2023-11-01 19:07:12 26 4
gpt4 key购买 nike

我有一个布局,其中包含另一个布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/layout1">

<include layout="@layout/my_layout"/>
</LinearLayout>

我需要在包含的布局中添加 RippleEffect 和 StateListAnimator。

例子:

<include layout="@layout/my_layout"
android:stateListAnimator="@anim/lift_up"
android:background="@drawable/ripple_effect"/>

RippleEffect 和 StateListAnimator 都 100% 工作。我无法更改包含的布局。这就是为什么我需要对包含标签或父布局本身产生影响的原因。

我已经尝试过这两种技术,但都没有成功。

UPDATE

如果可能,这应该以编程方式关闭。

UPDATE 2

其次,how would I go about keep the View elevated ,一旦它有动画?

最佳答案

您需要找到 View 并调用适当的方法来更改状态列表动画器和背景。您可能还需要在包含布局的 Root View 上调用 setClickable。

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

关于Android: <include> 与 RippleEffect & StateListAnimator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34673988/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com