我在滚动视图内部有约束布局。我正在尝试使用约束布局动画。它在滚动视图之外工作完美,但是当我想在滚动视图中使用它时,Android工作室说:android.support.v4.widget.NestedScrollView cannot be cast to android.support.constraint.ConstraintLayout我知道它,因为我的根布局是滚动视图,但我不知道如何解决这个问题。我试图在 ScrollView 之前添加另一个约束布局,这次 APP 工作正常而没有崩溃,但当我按下按钮时,没有任何反应。<android.support.v4.widget.NestedScrollView android:id="@+id/scrollView2"android:layout_width="match_parent"android:layout_height="match_parent"android:fillViewport="true"><android.support.constraint.ConstraintLayout android:id="@+id/const1" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/background_light" tools:context=".MainActivity">这就是我在主活动中所做的ConstraintSet constraintSet = new ConstraintSet();constraintSet.clone(this, R.layout.activity_main_animation);ChangeBounds transition = new ChangeBounds();transition.setInterpolator(new AnticipateInterpolator(1.0f));transition.setDuration(1200);TransitionManager.beginDelayedTransition(cc1, transition);constraintSet.applyTo(cc1);
2 回答

胡说叔叔
TA贡献1804条经验 获得超8个赞
更改以下代码
ConstraintSet constraintSet = new ConstraintSet();
constraintSet.clone(this, R.layout.activity_main_animation); //this line need to be changed to
constraintSet.clone(this, const1);// Pass id of ConstraintLayout for cloning as root layout of your xml file is not a ConstraintLayout.

慕尼黑的夜晚无繁华
TA贡献1864条经验 获得超6个赞
如果您不介意对视图中的所有布局更改进行动画处理,则可以尝试以下操作。添加并查看它是否适用于您的用例非常简单。加:
android:animateLayoutChanges="true"
添加到嵌套滚动视图并关闭所有过渡。每当您更改视图的边界或在屏幕上或屏幕外带来新内容时,Android都会自动处理动画。再次YMMV,因为你无法控制动画的速度等,但它值得一试。
添加回答
举报
0/150
提交
取消