布局中
<ViewPager2 android:id="@+id/live_viewpager" android:layout_width="match_parent" android:layout_height="0dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/live_divider_b" />
layout_height高度是0dp的时候,viewpager中Fragment中如果有可展开的TextVew时
textView展开效果不实现
我猜测是viewpager因为高度没确定,子控件认为空间有限不会伸展,具体原因没有深究
然后layout_height改成自适应子控件可以展开,但是layout_constraintTop_toBottomOf属性会失效
也就是约束布局失效了
然后试了各种方法改变layout_constraintTop_toBottomOf的约束也不可以同时满足需求
重点来了:
<RelativeLayout android:layout_width="match_parent" android:layout_height="0dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/live_divider_b"> <com.iqilu.core.view.ViewPager2 android:id="@+id/live_viewpager" android:layout_width="match_parent" android:layout_height="match_parent" /> </RelativeLayout>
viewPager外面嵌套一层RelativeLayout,运行,可以了
外面嵌套ConstraintLayout,LinearLayout都不行,就RelativeLayout可以
具体的原理没有深究