我在滾動視圖內部有約束布局。我正在嘗試使用約束布局動畫。它在滾動視圖之外工作完美,但是當我想在滾動視圖中使用它時,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
提交
取消