ConstraintLayout中Viewpager高度自适应layout_constraintTop_toBottomOf问题

布局中

<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可以

具体的原理没有深究

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

csdn_zxw

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值