Android仿京东商品详情页上拉查看图文详情

【参考借鉴】 Android仿京东、天猫商品详情页

首先看一下效果图

GIF图片太大了,就看一下截图吧。想看效果的去下载apk。【各位小可爱们如果觉得效果需要,可以小小的赞赏一下~~么么哒】


001.png
002.png
003.png
一、项目结构分析

1、顶部是TabLayout+ViewPager来实现,主要处理在DetailFragment中。布局中最外层是CoordinatorLayout,其次是自定义的一个view,slideDetailsLayout。来看一下detailFragment的布局文件。

<android.support.design.widget.CoordinatorLayout
        android:layout_above="@id/goodDetail_bottomLinearId"
        android:layout_alignParentTop="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.zxh.taobaogooddetail.views.SlideDetailsLayout
            android:id="@+id/slideDetailsLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/backgroundWhite">

            <ScrollView
                android:id="@+id/scrollView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scrollbars="vertical">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:background="@color/backgroundGray">
                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">
                        <com.youth.banner.Banner
                            android:id="@+id/detail_banner"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content">
                        </com.youth.banner.Banner>
                    </RelativeLayout>

                    <View style="@style/common_horizontal_line" />
                    <TextView
                        style="@style/style_black_s15"
                        android:background="@color/backgroundWhite"
                        android:ellipsize="end"
                        android:lineSpacingMultiplier="1.3"
                        android:maxLines="2"
                        android:text="雀巢(Nestle)咖啡1+2原味速溶咖啡饮品100条1500g(新老包装随机发货)" />

                    <LinearLayout
                        android:background="@color/backgroundWhite"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:padding="10dp">

                        <TextView
                            style="@style/style_red_s18"
                            android:layout_marginLeft="3dp"
                            android:text="¥99.00"
                            android:textStyle="bold" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:textSize="15sp"
                            android:layout_marginLeft="4dp"
                            android:text="¥120" />
                    </LinearLayout>
                    <LinearLayout
                        android:layout_marginTop="12dp"
                        android:padding="2dp"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="@color/backgroundWhite"
                        android:gravity="center_vertical">
                        <TextView
                            style="@style/style_black_s15"
                            android:layout_width="wrap_content"
                            android:text="促销"
                            android:textColor="#888888"/>
                        <TextView
                            style="@style/style_black_s15"
                            android:layout_width="0dp"
                            android:layout_weight="1"
                            android:ellipsize="end"
                            android:maxLines="1"
                            android:text="购买2-3件可享受每件9折"/>
                        <ImageView
                            android:layout_marginRight="10dp"
                            android:layout_width="24dp"
                            android:layout_height="wrap_content"
                            android:src="@mipmap/more"/>
                    </LinearLayout>
                    <LinearLayout
                        android:background="@color/backgroundWhite"
                        android:layout_marginTop="12dp"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">
                        <TextView
                            style="@style/style_black_s15"
                            android:layout_width="wrap_content"
                            android:text="已选"
                            android:textColor="#888888"/>
                        <TextView
                            style="@style/style_black_s15"
                            android:layout_width="0dp"
                            android:layout_weight="1"
                            android:ellipsize="end"
                            android:maxLines="1"
                            android:text="原味100条,1件"/>
                    </LinearLayout>

                    <LinearLayout
                        android:layout_marginTop="12dp"
                        android:background="@color/backgroundWhite"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical">
                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:gravity="center_vertical">
                            <TextView
                                style="@style/style_black_s15"
                                android:layout_width="wrap_content"
                                android:text="送至"
                                android:textColor="#888888"/>
                            <ImageView
                                android:layout_width="14dp"
                                android:layout_height="14dp"
                                android:src="@mipmap/address"/>
                            <TextView
                                style="@style/style_black_s15"
                                android:layout_width="0dp"
                                android:layout_weight="1"
                                android:ellipsize="end"
                                android:maxLines="1"
                                android:text="北京>朝阳区>三环以内"/>
                            <ImageView
                                android:layout_marginRight="10dp"
                                android:layout_width="24dp"
                                android:layout_height="wrap_content"
                                android:src="@mipmap/more"/>
                        </LinearLayout>
                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:gravity="center_vertical">
                            <TextView
                                android:visibility="invisible"
                                style="@style/style_black_s15"
                                android:layout_width="wrap_content"
                                android:text="重量"
                                android:textColor="#888888"/>
                            <TextView
                                style="@style/style_black_s15"
                                android:layout_width="wrap_content"
                                android:text="现货"
                                android:textColor="@color/mainColor"/>
                            <TextView
                                style="@style/style_black_s15"
                                android:layout_width="0dp"
                                android:layout_weight="1"
                                android:ellipsize="end"
                                android:maxLines="1"
                                android:text="15:00下单,可预约今晚送达"
                                android:textColor="#888888"/>
                        </LinearLayout>
                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:gravity="center_vertical">
                            <TextView
                                style="@style/style_black_s15"
                                android:layout_width="wrap_content"
                                android:text="重量"
                                android:textColor="#888888"/>
                            <TextView
                                style="@style/style_black_s15"
                                android:layout_width="0dp"
                                android:layout_weight="1"
                                android:ellipsize="end"
                                android:maxLines="1"
                                android:text="1200g"/>
                        </LinearLayout>
                    </LinearLayout>
                    <LinearLayout
                        android:layout_marginTop="12dp"
                        android:background="@color/backgroundWhite"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical">
                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:gravity="center_vertical">
                            <TextView
                                style="@style/style_black_s15"
                                android:layout_width="wrap_content"
                                android:text="评论(1080)"
                                android:textColor="#888888"/>
                            <TextView
                                style="@style/style_black_s15"
                                android:layout_width="0dp"
                                android:layout_weight="1"/>
                            <TextView
                                style="@style/style_black_s15"
                                android:layout_width="wrap_content"
                                android:text="好评度"/>
                            <TextView
                                android:layout_marginRight="10dp"
                                android:layout_height="wrap_content"
                                android:layout_width="wrap_content"
                                android:text="100%"
                                android:textSize="15sp"
                                android:textColor="@color/mainColor"/>
                        </LinearLayout>
                        <View style="@style/common_horizontal_line" />
                        <LinearLayout
                            android:orientation="vertical"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:padding="12dp">
                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:gravity="center_vertical">
                                <ImageView
                                    android:layout_width="32dp"
                                    android:layout_height="32dp"
                                    android:src="@mipmap/head"/>
                                <TextView
                                    style="@style/style_black_s15"
                                    android:layout_width="wrap_content"
                                    android:text="隐***膀"/>
                                <TextView
                                    style="@style/style_black_s15"
                                    android:layout_width="0dp"
                                    android:layout_weight="1"/>
                                <ImageView
                                    android:layout_width="12dp"
                                    android:layout_height="12dp"
                                    android:src="@mipmap/star"/>
                                <ImageView
                                    android:layout_width="12dp"
                                    android:layout_height="12dp"
                                    android:src="@mipmap/star"/>
                                <ImageView
                                    android:layout_width="12dp"
                                    android:layout_height="12dp"
                                    android:src="@mipmap/star"/>
                                <ImageView
                                    android:layout_width="12dp"
                                    android:layout_height="12dp"
                                    android:src="@mipmap/star"/>
                                <ImageView
                                    android:layout_width="12dp"
                                    android:layout_height="12dp"
                                    android:src="@mipmap/star"/>
                            </LinearLayout>
                            <TextView
                                android:layout_marginTop="10dp"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:background="@color/backgroundWhite"
                                android:ellipsize="end"
                                android:lineSpacingMultiplier="1.3"
                                android:maxLines="2"
                                android:textColor="#555555"
                                android:text="发货速度快,早上下单,下午就收到货了。都是用小纸箱装好的,日期也新鲜,准备每天早晚都冲一杯蜂蜜水喝喝。" />
                            <LinearLayout
                                android:orientation="horizontal"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content">
                                <com.zxh.taobaogooddetail.views.MyImageView
                                    android:layout_width="0dp"
                                    android:layout_weight="1"
                                    android:layout_height="wrap_content"
                                    android:src="@mipmap/goods_img01"
                                    android:scaleType="fitXY"/>
                                <View
                                    android:layout_width="8dp"
                                    android:layout_height="wrap_content"/>
                                <com.zxh.taobaogooddetail.views.MyImageView
                                    android:layout_width="0dp"
                                    android:layout_weight="1"
                                    android:layout_height="wrap_content"
                                    android:src="@mipmap/goods_img02"
                                    android:scaleType="fitXY"/>
                                <View
                                    android:layout_width="8dp"
                                    android:layout_height="wrap_content"/>
                                <com.zxh.taobaogooddetail.views.MyImageView
                                    android:layout_width="0dp"
                                    android:layout_weight="1"
                                    android:layout_height="wrap_content"
                                    android:src="@mipmap/goods_img03"
                                    android:scaleType="fitXY"/>
                                <View
                                    android:layout_width="8dp"
                                    android:layout_height="wrap_content"/>
                                <com.zxh.taobaogooddetail.views.MyImageView
                                    android:layout_width="0dp"
                                    android:layout_weight="1"
                                    android:layout_height="wrap_content"
                                    android:src="@mipmap/goods_img04"
                                    android:scaleType="fitXY"/>
                            </LinearLayout>
                        </LinearLayout>
                    </LinearLayout>
                    <RelativeLayout
                        android:id="@+id/detail_allCommentRelative"
                        android:layout_marginTop="2dp"
                        android:layout_marginRight="8dp"
                        android:layout_marginLeft="8dp"
                        android:background="@drawable/login_btn_bg"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:padding="12dp">
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="全部评价"
                            android:textSize="14sp"
                            android:textColor="#888888"
                            android:layout_centerInParent="true"/>
                    </RelativeLayout>


                    <!-- 上拉查看图文详情 -->
                    <LinearLayout
                        android:id="@+id/pull_up_view"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="@color/backgroundWhite"
                        android:gravity="center_vertical"
                        android:padding="12dp"
                        android:orientation="horizontal">
                        <View
                            android:layout_width="0dp"
                            android:layout_weight="1"
                            android:layout_height="2px"
                            android:background="@color/divide"/>
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="继续拖动,查看图文详情"
                            android:paddingLeft="12px"
                            android:paddingRight="12px"
                            android:textSize="12sp"
                            android:textColor="#888888"/>
                        <View
                            android:layout_width="0dp"
                            android:layout_weight="1"
                            android:layout_height="2px"
                            android:background="@color/divide"/>
                    </LinearLayout>
                </LinearLayout>
            </ScrollView>

            <include layout="@layout/include_item_tab" />
        </com.zxh.taobaogooddetail.views.SlideDetailsLayout>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab_up"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_margin="30dp"
            android:src="@mipmap/top"
            app:backgroundTint="#ffffff"
            app:borderWidth="0dp"
            app:fabSize="mini"
            app:rippleColor="#ffffff" />
    </android.support.design.widget.CoordinatorLayout>

2、SlideDetailsLayout实现setOnSlideDetailsListener监听事件,滑动操作的处理主要在这里执行。

@Override
    public void onStatusChanged(SlideDetailsLayout.Status status) {
        //当前为图文详情页
        if (status == SlideDetailsLayout.Status.OPEN) {
            fabUp.show();
            activity.operaTitleBar(true, true, false);
        } else {
            //当前为商品详情页
            fabUp.hide();
            activity.operaTitleBar(false, false, true);
        }
    }

3、图文详情中的自定义WebView.

public class ItemWebView extends WebView {
    public float oldY;
    private int t;
    private float oldX;

    public ItemWebView(Context context) {
        super(context);
    }

    public ItemWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ItemWebView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    @Override
    public boolean onTouchEvent(MotionEvent ev) {

        switch (ev.getAction()) {
            case MotionEvent.ACTION_MOVE:
                float Y = ev.getY();
                float Ys = Y - oldY;
                float X = ev.getX();

                if (Ys > 0 && t == 0) {
                    getParent().getParent().requestDisallowInterceptTouchEvent(false);
                }
                break;

            case MotionEvent.ACTION_DOWN:
                getParent().getParent().requestDisallowInterceptTouchEvent(true);
                oldY = ev.getY();
                oldX = ev.getX();
                break;

            case MotionEvent.ACTION_UP:
                getParent().getParent().requestDisallowInterceptTouchEvent(true);
                break;

            default:
                break;
        }
        return super.onTouchEvent(ev);
    }

    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        this.t = t;
        super.onScrollChanged(l, t, oldl, oldt);
    }

详细参考:

Android仿京东商品详情页上拉查看图文详情

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,458评论 4 363
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,454评论 1 294
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,171评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,062评论 0 207
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,440评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,661评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,906评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,609评论 0 200
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,379评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,600评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,085评论 1 261
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,409评论 2 254
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,072评论 3 237
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,088评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,860评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,704评论 2 276
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,608评论 2 270

推荐阅读更多精彩内容