ConstraintLayout布局内容被手机底部导航条遮住问题

本文讨论了在使用ConstraintLayout时,内容被手机底部导航条遮住的问题。作者指出,当导航栏出现时,布局的最下方部分会被遮挡,导致ScrollView无法滑动展示全部内容。为了解决这个问题,作者排除了使用layout_marginBottom和切换回LinearLayout或RelativeLayout的方法,并提供了官方推荐的解决方案:在布局文件中添加`app:layout_constraintBottom_toBottomOf="parent"`和`android:layout_height="0dp"`,这两个属性同时存在才能生效,避免了内容被遮挡的问题。
摘要由CSDN通过智能技术生成

ConstraintLayout约束布局,谷歌官方推荐的布局,Android2.3(API9)以后都可以使用此布局,与其他布局相比其可以很好的减少布局的层次,提升性能,结合RelativeLayout,LinearLayout等布局使用可以最大限度的减小界面的复杂度

大多人对这种布局还是比较陌生,熟练后你就会发现他的强大

ConstraintLayout的具体使用这里先不说了,网上有此内容,而且也是很简单的,只要你去用了,多用几次就很容易上手了

这里分享一个在使用ConstraintLayout布局遇到的问题

 

  • 问题描述

                             

异常现象:如上图界面,图2显示了底部导航栏后会将界面最底下部份遮住,此时布局中就算有ScrollView照样无法滑动显示,就是说此种布局状态下导航栏会将我们的内容遮住部份

正常现象:导航栏显示后会将整体界面上移,这是ScrollView就会有滑动效果了,内容也就不会被遮住

  • 解决思路

1,layout_marginBottom 缺点:强制间距,不能兼容多类型手机

2,使用LinearLayout或RelativeLayout:经验证其他布局不会有此问题,缺点:回到老路了,我们是要使用约束布局

  • 最终解决办法

简单...

在布局文件中加入下面的代码可以规避此问题

app:layout_constraintBottom_toBottomOf="parent"

android:layout_height="0dp" 官方推荐的写法,不再推荐使用match_parent

注意:上面两个属性得同时存在,不然不会生效

  • 布局文件
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:zhy="http://schemas.android.com/tools">

    <include
        android:id="@+id/ic_title"
        layout="@layout/activity_title"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/ic_title"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_height="0dp">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <TextView
                android:id="@+id/tv_tip"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/dp_24"
                android:layout_marginTop="@dimen/dp_10"
                android:gravity="center"
                android:text&#
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值