仿京东、淘宝商品详情页上拉显示详情的嵌套ScrollView

  • 开发背景:在做安卓商城项目时,产品经理老是拿京东和淘宝做样板,然后,就有了这个demo,实现在商品详情页上拉显示详情,主要技术就是处理ScrollView嵌套ScrollView或WebView时触摸、滑动事件的交互处理

  • 开发环境是eclipse,也会提供AS版本的源码
    1、看一下效果图:

2、看一下项目的目录结构:
目录结构

只有一个包,其中SlidingMenu,是最顶级的那个ScrollView,可以在其中包含连个ScrollView,或者WebView.

YsnowScrollViewPageOne.java:是两个ScrollView中的第一页,也就是最先展示的那个。

YsnowScrollView或YsnowWebView是第二页。

具体的代码大家下载源码自己看,注释很清楚了。

这里讲一下怎么快速集成进自己的项目:

  • 首先,将SlidingMenu.java、YsnowScrollView.java、YsnowScrollViewPageOne.java、YsnowWebView.java 拷贝到自己的项目中。

  • 然后,在需要的布局中引用如下:

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

    <ysnow.ysnowsslidingmenu.SlidingMenu
        android:id="@+id/expanded_menu"
        android:scrollbars="none"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >

        <ysnow.ysnowsslidingmenu.YsnowScrollViewPageOne
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#ffffff"
            android:scrollbars="vertical"
            >
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:background="@drawable/a"
                >
                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="1400dp"
                    />

            </LinearLayout>
        </ysnow.ysnowsslidingmenu.YsnowScrollViewPageOne>


            <ysnow.ysnowsslidingmenu.YsnowWebView
                android:id="@+id/ysnowswebview"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"

                >
                </ysnow.ysnowsslidingmenu.YsnowWebView>

        </LinearLayout>

        </ysnow.ysnowsslidingmenu.SlidingMenu>


</RelativeLayout>
  • 再然后,就可以了,是不是非常简单^^

最后献上源码:eclipse版AS版

扫描二维码关注公众号,回复: 2690446 查看本文章
欢迎关注我的个人公众号(捯饬捯饬啥)

daochidaochisha

猜你喜欢

转载自blog.csdn.net/yong531315/article/details/46361043