嵌套滚动视图无法转换为 android.support.constraint.

我在滚动视图内部有约束布局。我正在尝试使用约束布局动画。它在滚动视图之外工作完美,但是当我想在滚动视图中使用它时,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);


哈士奇WWW
浏览 92回答 2
2回答

胡说叔叔

更改以下代码ConstraintSet constraintSet = new ConstraintSet();constraintSet.clone(this, R.layout.activity_main_animation); //this line need to be changed to&nbsp;constraintSet.clone(this, const1);// Pass id of ConstraintLayout for cloning as root layout of your xml file is not a ConstraintLayout.

慕尼黑的夜晚无繁华

如果您不介意对视图中的所有布局更改进行动画处理,则可以尝试以下操作。添加并查看它是否适用于您的用例非常简单。加:&nbsp;&nbsp;&nbsp;&nbsp;android:animateLayoutChanges="true"添加到嵌套滚动视图并关闭所有过渡。每当您更改视图的边界或在屏幕上或屏幕外带来新内容时,Android都会自动处理动画。再次YMMV,因为你无法控制动画的速度等,但它值得一试。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java