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

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

相关推荐
雨白2 小时前
Jetpack系列(三):Room数据库——从增删改查到数据库平滑升级
android·android jetpack
花王江不语5 小时前
android studio 配置硬件加速 haxm
android·ide·android studio
江太翁7 小时前
mediapipe流水线分析 三
android·mediapipe
与火星的孩子对话8 小时前
Unity进阶课程【六】Android、ios、Pad 终端设备打包局域网IP调试、USB调试、性能检测、控制台打印日志等、C#
android·unity·ios·c#·ip
tmacfrank9 小时前
Android 网络全栈攻略(四)—— TCPIP 协议族与 HTTPS 协议
android·网络·https
fundroid10 小时前
Kotlin 协程:Channel 与 Flow 深度对比及 Channel 使用指南
android·kotlin·协程
草字10 小时前
cocos 打包安卓
android
DeBuggggggg11 小时前
centos 7.6安装mysql8
android
浩浩测试一下12 小时前
渗透信息收集- Web应用漏洞与指纹信息收集以及情报收集
android·前端·安全·web安全·网络安全·安全架构
移动开发者1号13 小时前
深入理解原子类与CAS无锁编程:原理、实战与优化
android·kotlin