当前位置: 首页 > news >正文

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.SwipeRefreshLayoutandroid:id="@+id/srl_drama"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_marginTop="73dp"><androidx.coordinatorlayout.widget.CoordinatorLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><com.google.android.material.appbar.AppBarLayoutandroid: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"><FrameLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"app:layout_scrollFlags="scroll"><FrameLayoutandroid:id="@+id/fl_normal_layout"android:layout_width="match_parent"android:layout_height="wrap_content"><ImageViewandroid: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" /><TextViewandroid: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><includeandroid:id="@+id/fl_vip_layout"layout="@layout/include_vip_banner"android:layout_width="match_parent"android:layout_height="wrap_content"android:visibility="gone" /></FrameLayout><includeandroid: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" /><includelayout="@layout/include_drama_category"android:layout_width="match_parent"android:layout_height="wrap_content" /></com.google.android.material.appbar.AppBarLayout><TableLayoutandroid:id="@+id/tablayout"android:layout_width="match_parent"android:layout_height="wrap_content"/><androidx.viewpager2.widget.ViewPager2android: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

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

http://www.lryc.cn/news/160598.html

相关文章:

  • 通过pyinstaller将python项目打包成exe执行文件
  • P1068 [NOIP2009 普及组] 分数线划定
  • 应用在汽车新风系统中消毒杀菌的UVC灯珠
  • TOOLLLM: FACILITATING LARGE LANGUAGE MODELS TO MASTER 16000+ REAL-WORLD APIS
  • 【JavaSpring】spring接口-beanfactory和applicationcontext与事件解耦
  • 《深入理解Java虚拟机》——Java内存区域与内存溢出异常
  • 公众号hanniman往期精选
  • 谷粒商城----缓存与分布式锁
  • 【JavaEE进阶】Spring事务和事务传播机制
  • 【Hive】drop table需注意外部表
  • 【2023数学建模国赛】A题定日镜场的优化设计模型建立
  • QT 事件与信号区别
  • [Vue3 博物馆管理系统] 使用Vue3、Element-plus tabs组件构建选项卡功能
  • 【算法专题突破】滑动窗口 - 长度最小的子数组(9)
  • 骨传导与入耳式耳机哪种音质好?该如何选择?
  • 【多线程】Timer任务定时器实现与盲等原子性问题的解决
  • SpringCloud-GetWay 路由网关
  • 使用生成式 AI 增强亚马逊云科技智能文档处理
  • 谈论浏览器内核
  • 电商卖家保障数据隐私和安全用什么安全的浏览器?
  • ECS通过DNAT将C非专线网段并网
  • g++模板显式实例化big file例子
  • Redis 删除策略
  • 自动化运维——ansible (五十二) (01)
  • 渗透测试漏洞原理之---【不安全的反序列化】
  • 建站系列(四)--- Web服务器之Apache、Nginx
  • TCP和UDP的区别
  • MBR、GPT、LVM分区
  • uniapp 下拉刷新
  • ifstream之seekg/tellg