Android仿京東商品詳情頁上拉查看圖文詳情

【參考借鑒】 Android仿京東土思、天貓商品詳情頁

首先看一下效果圖

GIF圖片太大了荷科,就看一下截圖吧。想看效果的去下載apk应狱±逊荩【各位小可愛們?nèi)绻X得效果需要绑嘹,可以小小的贊賞一下~~么么噠】


001.png
002.png
003.png
一稽荧、項目結構分析

1、頂部是TabLayout+ViewPager來實現(xiàn)工腋,主要處理在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(新老包裝隨機發(fā)貨)" />

                    <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="北京>朝陽區(qū)>三環(huán)以內(nèi)"/>
                            <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="現(xiàn)貨"
                                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="發(fā)貨速度快,早上下單箱歧,下午就收到貨了矾飞。都是用小紙箱裝好的,日期也新鮮呀邢,準備每天早晚都沖一杯蜂蜜水喝喝洒沦。" />
                            <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="繼續(xù)拖動,查看圖文詳情"
                            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實現(xiàn)setOnSlideDetailsListener監(jiān)聽事件价淌,滑動操作的處理主要在這里執(zhí)行申眼。

@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仿京東商品詳情頁上拉查看圖文詳情

最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末蝉衣,一起剝皮案震驚了整個濱河市括尸,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌病毡,老刑警劉巖濒翻,帶你破解...
    沈念sama閱讀 212,080評論 6 493
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異啦膜,居然都是意外死亡有送,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,422評論 3 385
  • 文/潘曉璐 我一進店門僧家,熙熙樓的掌柜王于貴愁眉苦臉地迎上來雀摘,“玉大人,你說我怎么就攤上這事八拱≌笤” “怎么了烁落?”我有些...
    開封第一講書人閱讀 157,630評論 0 348
  • 文/不壞的土叔 我叫張陵,是天一觀的道長豌注。 經(jīng)常有香客問我,道長灯萍,這世上最難降的妖魔是什么轧铁? 我笑而不...
    開封第一講書人閱讀 56,554評論 1 284
  • 正文 為了忘掉前任,我火速辦了婚禮旦棉,結果婚禮上齿风,老公的妹妹穿的比我還像新娘。我一直安慰自己绑洛,他們只是感情好救斑,可當我...
    茶點故事閱讀 65,662評論 6 386
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著真屯,像睡著了一般脸候。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上绑蔫,一...
    開封第一講書人閱讀 49,856評論 1 290
  • 那天运沦,我揣著相機與錄音,去河邊找鬼配深。 笑死携添,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的篓叶。 我是一名探鬼主播烈掠,決...
    沈念sama閱讀 39,014評論 3 408
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼缸托!你這毒婦竟也來了左敌?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 37,752評論 0 268
  • 序言:老撾萬榮一對情侶失蹤嗦董,失蹤者是張志新(化名)和其女友劉穎母谎,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體京革,經(jīng)...
    沈念sama閱讀 44,212評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡奇唤,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,541評論 2 327
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了匹摇。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片咬扇。...
    茶點故事閱讀 38,687評論 1 341
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖廊勃,靈堂內(nèi)的尸體忽然破棺而出懈贺,到底是詐尸還是另有隱情经窖,我是刑警寧澤,帶...
    沈念sama閱讀 34,347評論 4 331
  • 正文 年R本政府宣布梭灿,位于F島的核電站画侣,受9級特大地震影響,放射性物質發(fā)生泄漏堡妒。R本人自食惡果不足惜配乱,卻給世界環(huán)境...
    茶點故事閱讀 39,973評論 3 315
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望皮迟。 院中可真熱鬧搬泥,春花似錦、人聲如沸伏尼。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,777評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽爆阶。三九已至燥透,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間扰她,已是汗流浹背兽掰。 一陣腳步聲響...
    開封第一講書人閱讀 32,006評論 1 266
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留徒役,地道東北人孽尽。 一個月前我還...
    沈念sama閱讀 46,406評論 2 360
  • 正文 我出身青樓,卻偏偏與公主長得像忧勿,于是被迫代替她去往敵國和親杉女。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 43,576評論 2 349

推薦閱讀更多精彩內(nèi)容