布局中
<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可以
具体的原理没有深究
当ViewPager2的layout_height设置为0dp时,其内部Fragment中的可展开TextView无法正常展开。作者推测原因是高度未确定导致子控件无法伸展。将height改为匹配子视图后,约束布局的约束top_to_bottom_of属性失效。通过在外面包裹一层RelativeLayout并保持height为0dp,问题得到解决,而使用ConstraintLayout或LinearLayout则无效。具体原因未深入探究。
2328

被折叠的 条评论
为什么被折叠?



