ConstraintLayout约束布局

1.进行复杂页面布局时,最外层的根布局不要用ConstraintLayout.

示例布局:

复制代码
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:background="@drawable/common_bg">

    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/srl_drama"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="73dp">

        <androidx.coordinatorlayout.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <com.google.android.material.appbar.AppBarLayout
                android:id="@+id/abl_drama"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="13dp"
                android:layout_marginEnd="13dp"
                android:background="@android:color/transparent"
                android:elevation="0dp"
                app:elevation="0dp">

                <FrameLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    app:layout_scrollFlags="scroll">

                    <FrameLayout
                        android:id="@+id/fl_normal_layout"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <ImageView
                            android:id="@+id/iv_banner"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:adjustViewBounds="true"
                            android:src="@drawable/tab1_banner"
                            app:layout_constraintLeft_toLeftOf="parent"
                            app:layout_constraintRight_toRightOf="parent"
                            app:layout_constraintTop_toTopOf="parent" />

                        <TextView
                            android:id="@+id/tv_drama_vip"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="bottom|start"
                            android:layout_marginStart="16dp"
                            android:layout_marginBottom="12dp"
                            android:background="@drawable/bg_purchase"
                            android:paddingStart="18dp"
                            android:paddingTop="8dp"
                            android:paddingEnd="18dp"
                            android:paddingBottom="8dp"
                            android:text="30元开通"
                            android:textColor="#FFFFFFFF"
                            android:textSize="18sp"
                            android:textStyle="bold" />

                    </FrameLayout>

                    <include
                        android:id="@+id/fl_vip_layout"
                        layout="@layout/include_vip_banner"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:visibility="gone" />

                </FrameLayout>


                <include
                    android:id="@+id/include_drama_history"
                    layout="@layout/header_drama"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="18dp"
                    android:layout_marginBottom="18dp"
                    app:layout_scrollFlags="scroll" />

                <include
                    layout="@layout/include_drama_category"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

            </com.google.android.material.appbar.AppBarLayout>

            <TableLayout
                android:id="@+id/tablayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>
            
            <androidx.viewpager2.widget.ViewPager2
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>

        </androidx.coordinatorlayout.widget.CoordinatorLayout>

    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

并且viewpaer的内容用的fragment,fragment布局里是RecyclerView

在这种复杂布局中,就遇到RecyclerView内容拉不到底部的问题。通过分析界面,发现是因为viewpager的布局已经超出屏幕了。

如何解决:

外层的根布局用RelativeLayout 或者 LinearLayout就能解决RecyclerView内容拉不到底部的问题

2.ConstraintLayout内嵌套NestedScrollView

注意:也会遇到内容显示不全的问题

相关推荐
AH_HH10 分钟前
SmartCabinet:基于 Android 的智能储物柜管理系统技术解析
android·kotlin·存储柜
西部风情12 分钟前
聊聊并发、在线、TPS
android·java·数据库
2501_916008895 小时前
Web 前端开发常用工具推荐与团队实践分享
android·前端·ios·小程序·uni-app·iphone·webview
我科绝伦(Huanhuan Zhou)6 小时前
MySQL一键升级脚本(5.7-8.0)
android·mysql·adb
怪兽20147 小时前
Android View, SurfaceView, GLSurfaceView 的区别
android·面试
龚礼鹏8 小时前
android 图像显示框架二——流程分析
android
消失的旧时光-19438 小时前
kmp需要技能
android·设计模式·kotlin
帅得不敢出门9 小时前
Linux服务器编译android报no space left on device导致失败的定位解决
android·linux·服务器
雨白9 小时前
协程间的通信管道 —— Kotlin Channel 详解
android·kotlin
TimeFine11 小时前
kotlin协程 容易被忽视的CompletableDeferred
android