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

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:l
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
如果自定义的底部TabBar遮住了页面内容,可以尝试以下解决方法: 1. 在`App.vue`的`<view class="app">`标签中添加一个底部留白的区域,以避免内容底部TabBar遮挡。 ```vue <template> <view class="app"> <router-view></router-view> <view class="tabbar-placeholder"></view> <uni-tab-bar> <!-- TabBar的内容 --> </uni-tab-bar> </view> </template> <style> .tabbar-placeholder { height: 50px; /* 底部TabBar的高度 */ } </style> ``` 通过添加一个高度和底部TabBar相同的留白区域,可以保证页面内容不被底部TabBar遮挡。 2. 调整页面内容的样式,避免与底部TabBar重叠。 可以通过设置页面内容的`margin-bottom`属性,给内容留出一定的空间,避免与底部TabBar重叠。 ```vue <style> .page-content { margin-bottom: 50px; /* 底部TabBar的高度 */ } </style> ``` 在页面的样式中,为内容容器添加一个`margin-bottom`属性,值为底部TabBar的高度,以确保内容不被TabBar遮挡。 3. 使用`position: fixed`固定底部TabBar的位置。 如果以上方法无效,可以尝试使用CSS的`position: fixed`将底部TabBar固定在页面底部,以确保内容不被遮挡。 ```vue <style> .uni-tab-bar { position: fixed; bottom: 0; left: 0; width: 100%; } </style> ``` 将底部TabBar的样式中添加`position: fixed`,并设置`bottom: 0`,`left: 0`,`width: 100%`等属性来固定在页面底部。 通过以上方法,你可以解决底部TabBar遮住页面内容问题。根据具体情况选择适合的方法即可。希望对你有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值