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

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

相关推荐
666xiaoniuzi4 小时前
深入理解 C 语言中的内存操作函数:memcpy、memmove、memset 和 memcmp
android·c语言·数据库
沐言人生8 小时前
Android10 Framework—Init进程-8.服务端属性文件创建和mmap映射
android
沐言人生8 小时前
Android10 Framework—Init进程-9.服务端属性值初始化
android·android studio·android jetpack
沐言人生9 小时前
Android10 Framework—Init进程-7.服务端属性安全上下文序列化
android·android studio·android jetpack
追光天使9 小时前
【Mac】和【安卓手机】 通过有线方式实现投屏
android·macos·智能手机·投屏·有线
小雨cc5566ru9 小时前
uniapp+Android智慧居家养老服务平台 0fjae微信小程序
android·微信小程序·uni-app
一切皆是定数10 小时前
Android车载——VehicleHal初始化(Android 11)
android·gitee
一切皆是定数10 小时前
Android车载——VehicleHal运行流程(Android 11)
android
problc10 小时前
Android 组件化利器:WMRouter 与 DRouter 的选择与实践
android·java
图王大胜11 小时前
Android SystemUI组件(11)SystemUIVisibility解读
android·framework·systemui·visibility