Android: <include> 与 RippleEffect & StateListAnimator

标签 android android-layout rippledrawable android-include

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

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

相关文章:

android - 如何在 View 内的特定位置触发 Android Lollipop 的涟漪效应,而不触发触摸事件?

android - 如何以编程方式设置 XML 波纹?

android - 服务中的 SurfaceView

android - Play 商店的设备兼容性问题

android - IllegalArgumentException : Invalid int: "OS" with Samsung tts

android - 如何在Android xml中制作两条平行且相邻的线?

java - Android Spinner 抛出 Java.lang.nullpointerexception - Android Beginner

android - 如何在android中的LinearLayout内左右对齐2张图片

Android - 在 ImageView 周围设置边框

android - 找不到类 'android.graphics.drawable.RippleDrawable'