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

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

相关推荐
yangpipi-1 小时前
《C++并发编程实战》第5章 C++内存模型和原子操作
android·java·c++
云水木石3 小时前
Android 的下一个战场:Windows 应用与游戏?
android·windows·游戏
雨声不在4 小时前
Android文字渐变的实现
android·textview
GoldenPlayer4 小时前
KTS语法
android
GoldenPlayer4 小时前
后台服务Service销毁逻辑+单例造成的内存泄露
android
GoldenPlayer4 小时前
自定义APK&gradle全局配置文件
android
うちは止水4 小时前
Android Hal层开发流程
android·hal
李小轰_Rex4 小时前
把手机变成听诊器!摄像头 30 秒隔空测心率 - 开箱即用
android·音视频开发
为码消得人憔悴6 小时前
Android perfetto - 记录分析memory
android·性能优化
尤老师FPGA6 小时前
使用ZYNQ芯片和LVGL框架实现用户高刷新UI设计系列教程(第四十二讲)
android·java·ui