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

如何在 ConstraintLayout 中将 ViewPager 始终置于 ll_title 的下方

关于如何在 ConstraintLayout 中将 ViewPager 始终置于 ll_title标题栏 的下方。。

如何将 ViewPager 始终置于 ll_title 下方

ConstraintLayout 中,可以通过约束来实现 ViewPager 始终位于 ll_title 标题栏的下方。以下是修改后的布局代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white">

    <!-- 标题栏 -->
    <RelativeLayout
        android:id="@+id/ll_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent">

      

        <LinearLayout
            android:id="@+id/ll_title_part"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:padding="5dp"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/commonTitle_iv_back"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:gravity="center"
                android:layout_marginTop="-10dp"
                android:padding="10dp"
                android:src="@drawable/smssdk_ic_popup_dialog_close" />
        </LinearLayout>
    </RelativeLayout>

    <!-- ViewPager -->
    <android.support.v4.view.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintTop_toBottomOf="@id/ll_title"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent" />
</android.support.constraint.ConstraintLayout>

关键点说明

  1. ll_title 的约束

    • app:layout_constraintTop_toTopOf="parent":将 ll_title 置于顶部。

    • app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent":让 ll_title 横向充满父布局。

  2. ViewPager 的约束

    • app:layout_constraintTop_toBottomOf="@id/ll_title":将 ViewPager 的顶部约束到 ll_title 的底部。

    • app:layout_constraintBottom_toBottomOf="parent":将 ViewPager 的底部约束到父布局的底部。

    • app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent":让 ViewPager 横向充满父布局。

    • android:layout_height="0dp":通过约束来分配高度,确保 ViewPager 填充剩余空间。

注意事项

  • 确保 ll_title 的高度不会过大,否则可能会挤压 ViewPager 的显示空间。

  • 如果 ViewPager 的内容较多,可以考虑设置滚动条或分页指示器,以提升用户体验。

通过上述布局代码,ViewPager 将始终位于 ll_title 的下方,并且会自动填充剩余空间。

http://www.dtcms.com/a/26579.html

相关文章:

  • 前端需要学习 Docker 吗?
  • 【运维】源码编译安装cmake
  • 【C++】The fundamentals of C++
  • Spring 接入 DeepSeek
  • AD(Altium Designer)器件封装——立创商城导出原理图和PCB完成器件封装操作指南
  • 达梦存储过程执行后 sql日志信息粗读
  • idea从远程gitee拉取项目
  • 2025国内十大iPaaS集成平台
  • 老游戏回顾:d2
  • GoFound 与 MySQL 集成优化方案
  • Coze扣子新功能详解
  • C++蓝桥杯基础篇(四)
  • RocketMQ消息是如何储存的?
  • 事务--实操演示
  • notepad++右键菜单不见了
  • Docker 私有仓库 Harbor 详解
  • Rust Slice(切片)类型
  • uniapp邪门事件
  • 【技术洞察】2024科技绘卷:浪潮、突破、未来
  • 算法刷题-哈希表的总结
  • CTF-RE: 基础模块-循环移位
  • scroll、offset、client三大家族和getBoundingClientRect方法
  • python concurrent.futures
  • 基于YOLO11深度学习的果园苹果检测与计数系统设计与实现【python源码+Pyqt5界面+数据集+训练代码】
  • 【Spring生命周期】Bean元信息配置阶段
  • Python Selenium自动化操作详解:从入门到实战
  • JavaScript中的函数基础知识
  • win10本地部署deepseek-r1步骤
  • 用户的声音 | 文档结构化信息提取方案测评:LLM、开源模型部署与云端API,谁是合适选择?
  • 在 Vue 项目中,为什么要在列表组件中写 key,其作用是什么?