ConstraintLayout不能居中问题

今天遇到一种情况,ConstraintLayout里面设置了一个TextView,且TextView也设置了自动和父容器顶部和底部相关联,但TextView就一直在ConstraintLayout的顶部,源码如下:

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="返回"
        android:textSize="18sp"
        app:layout_constraintLeft_toRightOf="@id/xxx"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"/>
</android.support.constraint.ConstraintLayout>

纠结了好久,突然发现TextView的布局高度设置成了match_parent,遂将其设置为wrap_content,OK,问题解决,最后代码如下,只是改了TextView的布局高度:

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="返回"
        android:textSize="18sp"
        app:layout_constraintLeft_toRightOf="@id/xxx"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"/>
</android.support.constraint.ConstraintLayout>

推测是当子布局的高度设置成和父容器高度一样高时,它本身也就没有上下移动的空间了,所以设置无效。

这仅是个人猜想,实际情况也不知道是不是这样,也希望能帮到在这和我一样迷惑的新手,若有知情者知道具体详情,望告知。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值