现在还在用上拉拖拽显示更多?淘宝都已经废弃了的效果还要继续使用吗!下面我们先来看看淘宝现在效果,右图是我实现的效果,其实还是很相近的,对吧!

ok,效果呢就是这样了,今天这里主要关注俩个地方,1、头部渐变 2、滚动到指定位置选显卡颜色做出相应的改变并且点击选项卡页面滑动到相应的位置

首先大家不要把这个想的多么多么难啊,其实实现起来很简单的,那我们看看实现方案吧!文章末尾,我会给出源码地址,大家互相学习哈!

1、布局activity_taobao_detail.xml

页面上一共有四个模块,我得分别是:商品、评价、详情、售后。这四个模块分别使用布局layout1、layout2、layout3、layout4将内容包裹起来。页面方便后面监听高度he点击选项卡滚动为主

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/detail_scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical"
        >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <LinearLayout
                android:id="@+id/layout1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                >
                <RelativeLayout
                    android:id="@+id/layout1_vp_rl"
                    android:layout_width="match_parent"
                    android:layout_height="300dp">
                    <android.support.v4.view.ViewPager
                        android:id="@+id/layout1_viewpager"
                        android:layout_width="match_parent"
                        android:layout_height="300dp">
                    </android.support.v4.view.ViewPager>

                    <TextView
                        android:id="@+id/layout1_text"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="0/0"
                        android:gravity="center_vertical"
                        android:layout_alignParentRight="true"
                        android:layout_alignParentBottom="true"
                        android:background="@drawable/xml_bg_gray_20_tra"
                        android:textColor="@color/color_fff"
                        android:layout_marginBottom="15dp"
                        android:layout_marginRight="20dp"
                        />

                </RelativeLayout>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="500dp"
                    android:background="#eeddaa"
                    android:text="dw9esad"
                    android:textColor="#33ddaa"/>
            </LinearLayout>

            <LinearLayout
                android:id="@+id/layout2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                >
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="40dp"
                    android:background="#dddddd"
                    android:text="商品评价"
                    android:textColor="#666"
                    android:gravity="center"/>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="800dp"
                    android:background="#33ddaa"
                    android:text="dw9esad"
                    android:textColor="#ddeeaa"/>
            </LinearLayout>
            <LinearLayout
                android:id="@+id/layout3"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                >
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="40dp"
                    android:background="#dddddd"
                    android:text="商品详情"
                    android:textColor="#666"
                    android:gravity="center"/>

                <WebView
                    android:id="@+id/layout3_webview"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/layout4"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                >
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="40dp"
                    android:background="#dddddd"
                    android:text="售后服务"
                    android:textColor="#666"
                    android:gravity="center"/>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="830dp"
                    android:background="#ee22ee"
                    android:text="dw9esad"
                    android:textColor="#eeaadd"/>
            </LinearLayout>
        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
    <include layout="@layout/layout_top"/>
    <include layout="@layout/layout"/>
</RelativeLayout>

可以看到我这里引入了两个布局,其实都是头部啦!命名啥的大家知道就好啊

layout_top.xml 这个头部呢,其实我只是作为效果的,页面上没有起到什么实际性的作用,就是个展示。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/top_layout2"
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:background="@android:color/transparent"
                android:gravity="center_vertical"
    >

    <ImageView
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:padding="8dp"
        android:src="@mipmap/back"/>

    <ImageView
        android:id="@+id/top_share1"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_alignParentRight="true"
        android:layout_marginLeft="8dp"
        android:padding="8dp"
        android:src="@mipmap/share"/>

    <ImageView
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_toLeftOf="@+id/top_share1"
        android:padding="8dp"
        android:src="@mipmap/shop_cart"/>
</RelativeLayout>

layout.xml   这个才是详细页真正意义上的头部,里面主要是用了一个tabLayout,当然大家也可以使用其他的方案实现。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:id="@+id/top_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/color_fff"
                android:paddingTop="8dp">

    <ImageView
        android:id="@+id/top_back"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:padding="8dp"
        android:src="@mipmap/back1"/>

    <ImageView
        android:id="@+id/top_share"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_alignParentRight="true"
        android:layout_marginLeft="8dp"
        android:padding="8dp"
        android:src="@mipmap/share1"/>

    <ImageView
        android:id="@+id/top_shop"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_toLeftOf="@+id/top_share"
        android:padding="8dp"
        android:src="@mipmap/shop_cart1"/>

    <ImageView
        android:id="@+id/top_img"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_centerHorizontal="true"
        android:scaleType="fitXY"
        android:src="@mipmap/gilder1"
        />

    <android.support.design.widget.TabLayout
        android:id="@+id/top_tab"
        android:layout_width="match_parent"
        android:layout_height="45dp"
        android:layout_below="@+id/top_img"
        app:tabIndicatorHeight="0dp"
        app:tabMode="fixed"
        app:tabSelectedTextColor="@color/colorPrimary"
        app:tabTextColor="@color/color_666"
        >

        <android.support.design.widget.TabItem
            android:id="@+id/top_tab_product"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="商品"/>

        <android.support.design.widget.TabItem
            android:id="@+id/top_tab_eva"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="评价"/>

        <android.support.design.widget.TabItem
            android:id="@+id/top_tab_detail"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="详情"/>

        <android.support.design.widget.TabItem
            android:id="@+id/top_tab_cusser"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="售后"/>
    </android.support.design.widget.TabLayout>

</RelativeLayout>

Ok布局全部内容就是这样了,下面我们来看看代码是怎么实现的吧。

一、透明度

首先实现scrollView的滚动监听,然后就是scrollYhe轮播图的高度比对,这里我是希望滑动超过轮播图的高度是带选项卡的头部(toplayout1)设为不透明,

使用setAlpha()直接设置控件的透明度,当然你可能在很多文档中看到top_layout.getBackground().mutate().setAlpha();这个方法来改变标题的透明度,这里我为什么没有用呢,主要是这个方法仅仅只是改变了这块布局的背景的透明的度,其中的子View不受影响。而我们希望的效果时整块布局都带有透明的效果(这里我要瞎掰扯一会了,我一开始当然是不知道,然后我就在布局里面先把toplayout1的xml 文件中将根布局透明度设置为全透明android:alpha="0",后来在代码中使用设置背景透明度的方法结果比起作用了,不要说我傻啊,凡事都个过程。)总之这个方法是可以的哦,两者的效果不一样罢了。

那个计算透明度的算法,大家看看就行了啊,这我也解释不好,毕竟是数学。

到此为止呢,透明度的基本上效果就实现了。

二、滚动到指定位置选显卡颜色做出相应的改变并且点击选项卡页面滑动到相应的位置

1、页面滚动到指定位置改变选项卡选中状态。

实现的方案就是简单的获取四部分内容距离头部的位置,getTop()获取的是距离父控件的高度,但是这里呢,恰好父控件是全屏的。然后就layout1.getTop();layut2,getTop();layout3.getTop();layout4.getTop();分别获取距离头部的高度。至于为什么要减去toplayout_height(toplayout1高度);是因为我希望他显示在头部的下面啊。是不是很简单。下面就是设置tab的选中状态了

2、点击选项卡滚动到指定位置。

这个感觉不用解释太多,相信大家都是可以看懂的,这个方法就是监听tab选重事件的嘛。

第一次写文章,大家不要笑话,本来语文教不好,多多包涵。

http://download.csdn.net/download/xinyu315/10042049,需要2个积分,我也很无奈,最少就选两个,没有积分的就私信我吧,留下联系方式哦,不过我不一定能看到呢。。

最新仿淘宝详细页头部渐变效果相关推荐

  1. 自定义View之仿淘宝详情页

    自定义View之仿淘宝详情页 转载请标明出处: http://blog.csdn.net/lisdye2/article/details/52353071 本文出自:[Alex_MaHao的博客] 项 ...

  2. 仿淘宝详情页 直接上代码

    仿淘宝详情页 直接上代码 package com.example.liketitledemo;import android.content.Context; import android.graphi ...

  3. 最新仿淘宝B站购物直播小程序+带货完整PHP源码下载

    正文: 最新仿淘宝B站购物直播小程序+带货完整PHP源码下载,由于演示图太长了,所以我分别载图了两张,完整的演示图直接发压缩包了,有兴趣自行去查看. 当前版本已经修复直播间相关的一些BUG,还有商品新 ...

  4. uniapp仿淘宝详情页页面滑动tab切换

    uniapp仿淘宝详情页页面滑动tab切换 建立util文件夹放一个Tool.js: export default{getRect(selector){return new Promise((reso ...

  5. 仿淘宝详情页的商品详情

    先上效果图 效果就是上面图片的效果 接下来看看如何实现 首先我们来看下布局文件 <LinearLayoutandroid:id="@+id/header"android:la ...

  6. Ecshop 商品页配送方式添加 实现仿淘宝按地区显示运费

    Ecshop实现仿淘宝按地区显示运费 淘宝网(Taobao)购物的宝贝详情页面,可以针对不同地区显示不同运费,运费由后台设定:结算时间,按重量.件数计算运费.Ecshop本身有配送方式插件,已有多家物 ...

  7. HTML5期末大作业:电商网站设计——仿淘宝电商网站管理系统21页(含毕业设计论文7500字) HTML+CSS+JavaScript

    HTML5期末大作业:电商网站设计--仿淘宝电商网站管理系统21页(含毕业设计论文7500字) HTML+CSS+JavaScript 常见网页设计作业题材有 个人. 美食. 公司. 学校. 旅游. ...

  8. Android 仿淘宝商品详情页下拉足迹Demo

    DropDownMultiPager 仿淘宝等商品详情页下拉足迹效果SimpleDemo 可colne之后看MainActivity的调用,方便二次开发 依赖 compile 'com.nineold ...

  9. 高仿淘宝和聚美优品商城详情页实现《IT蓝豹》

    高仿淘宝和聚美优品商城详情页实现 android-vertical-slide-view高仿淘宝和聚美优品商城详情页实现,在商品详情页,向上拖动时,可以加载下一页. 使用ViewDragHelper, ...

  10. HTML5期末大作业:仿淘宝电商网站设计——仿淘宝电商管理系统(21页)含论文 HTML+CSS+JavaScript 学生DW网页设计作业成品 大学生网页制作期末作业

    HTML5期末大作业:仿淘宝电商网站设计--仿淘宝电商管理系统(21页)含论文 HTML+CSS+JavaScript 学生DW网页设计作业成品 大学生网页制作期末作业 常见网页设计作业题材有 个人. ...

最新文章

  1. 面板——卡片面板、常规折叠面板、手风琴折叠
  2. 最短路径Dijkstra讲解,工具包使用 python
  3. 树莓派更换软件源提高下载速度
  4. IBASE read buffer
  5. 多线程之继承Thread类及多线程内存分析
  6. 分数优先遵循志愿php源码_2021年南昌中考志愿填报指导,这七大要点你都了解吗?...
  7. 吴军:为什么计算机不是万能的
  8. mysql 存储过程 行锁_mysql存储过程出现锁表锁行的情况怎么解决?如:
  9. 英特尔:5G将释放云的潜力,为垂直行业带来巨大商机
  10. c语言传址函数,关于c语言函数传址的规定
  11. input 禁止 复制 粘贴 剪切 操作
  12. 图书条形码跟ISBN号互相转换的类 续
  13. python 文件格式转换_如何把txt文件转换成py文件
  14. 如何修改植物大战僵尸金币
  15. Sigmod 和 Logit
  16. 数字化时代-15:从商品交换过程解剖淘宝电商
  17. 连米哈游都成了第二,这个一刀999的页游大王把老外吃透了。
  18. Ubuntu系统升级后无法进入系统
  19. 卓懿9.0正式版来袭
  20. ZZULIOJ1075: 聚餐人数统计

热门文章

  1. ESP8266开发之旅 网络篇④ Station——ESP8266WiFiSTA库的使用
  2. TextRank算法讲解与代码实现
  3. RxView学习及实现按钮防抖功能
  4. linux 卸载oracle库,Linux下完美卸载 Oracle
  5. 4.10招商银行笔试编程题
  6. OrCAD中PSpice K_Linear以及变压器的使用方法
  7. 利器 | REST Assured 实践(二):断言实现
  8. 服务器防火墙部分指令
  9. 最新封装版EVE模拟器部署和使用说明(图文版)
  10. chrome(谷歌浏览器)固定到任务栏,点击之后出现两个图标