Android 仿京东上滑效果

前言:

现在很多app首页的结构都有头部广告,上滑固定toolbar及侧滑广告位等展示,典型的比如招商银行app,支付宝、哈罗单车、京东、苏宁金融也有类似的效果。具体如下,左侧为有广告位存在的情况,右侧无顶部广告位的样式:

                         

效果说明:头部广告一般在节假日有活动的时候展示,页面上滑会有固定标题栏展示,靠底部右侧有一个小的广告位,滑动主屏幕时,广告位会向右侧收起,屏幕不滚动时,广告位显示。本文旨在为实现这种效果提供一种方式,欢迎有其他想法的小伙伴评论交流,接下来将分三块分别实现顶部广告位,滑动固定toolbar及侧滑广告位效果。

顶部广告位:

分析:有广告位图片和没广告位图片的区别在于下方白色内容区域在图片下方还是在顶部4个功能项的下方,一种方式:根据是否有广告位动态调整margin高度;方式二:使用约束布局,根据情况改变白色区域内容相对谁来布局

实现:

这里我们使用第二种方式实现:

外层父布局为ConstraintLayout,里面内容包含三部分:

1. 底部背景ImageView控件A,有图片时设置src,无图时设置background;

2. 四个功能选项部分B,即无图时白色区域的约束对象;

3. 白色内容区域C,无图时约束对象为B,有图时约束对象为A;

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/cl_header"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
    android:id="@+id/iv_bg_header"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:background="@drawable/shape_gradient_yellow"
    android:contentDescription="@null"
    android:scaleType="fitXY"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<LinearLayout
    android:id="@+id/ll_search"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="12dp"
    android:layout_marginTop="50dp"
    android:layout_marginEnd="12dp"
    android:clickable="true"
    android:gravity="center_vertical"
    android:orientation="horizontal"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <EditText
 
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值