滚动固定的ViewPager视图

3

我正在尝试使用嵌套滚动条来滚动固定的viewpager。问题是我能够在固定的viewpager上滚动内容,但我无法滑动viewpager以更改产品图片。我尝试了CollapsingToolbar,但它没有起作用。因此,我开发了另一个布局,它可以做到我想要的事情,但问题是它与viewpager不兼容。这是我的当前布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="org.kiranahouse.activity.SingleProductActivity">
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:elevation="0dp"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            app:collapseIcon="@drawable/back_colored"
            app:contentInsetLeft="0dp"
            app:contentInsetStart="0dp"
            app:contentInsetStartWithNavigation="0dp">
        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.AppBarLayout>
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <android.support.v4.view.ViewPager
            android:id="@+id/product_image_pager"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_marginTop="60dp">
        </android.support.v4.view.ViewPager>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="24dp"
            android:layout_below="@+id/product_image_pager">
            <android.support.design.widget.TabLayout
                android:layout_width="match_parent"
                android:layout_height="24dp"
                android:id="@+id/pager_tab_layout"
                app:tabBackground="@drawable/tab_selector"
                app:tabIndicatorHeight="0dp"
                app:tabGravity="center">
            </android.support.design.widget.TabLayout>
        </LinearLayout>
    </RelativeLayout>
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
        <android.support.v4.widget.NestedScrollView
            android:id="@+id/nestedScroll"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbars="vertical"
            android:elevation="12dp"
            android:layout_marginBottom="56dp">
            <LinearLayout
                android:paddingTop="250dp"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"
                    android:background="#fafafa">
                    <android.support.v7.widget.CardView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:elevation="4dp"
                        app:cardCornerRadius="2dp">
                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:orientation="vertical">
                            <RelativeLayout
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:padding="16dp">
                                <org.kiranahouse.component.CustomTextView
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:text="Product Name"
                                    android:textColor="@color/normalButtonGradientEnd"
                                    android:ellipsize="end"
                                    android:textAppearance="?android:attr/textAppearanceMedium"
                                    android:id="@+id/product_title"/>
                                <RelativeLayout
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:layout_below="@+id/product_title"
                                    android:layout_marginTop="8dp">
                                    <org.kiranahouse.component.CustomTextView
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:ellipsize="end"
                                        android:layout_alignParentLeft="true"
                                        android:text="Rs. 1024"
                                        android:id="@+id/actual_price"
                                        android:textAppearance="?android:attr/textAppearanceLarge"
                                        android:textColor="@color/primaryTextColor"
                                        android:layout_centerVertical="true"/>
                                    <org.kiranahouse.component.CustomTextView
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:layout_toRightOf="@+id/actual_price"
                                        android:layout_marginLeft="16dp"
                                        android:text="Rs. 2999"
                                        android:id="@+id/old_price"
                                        android:layout_centerVertical="true"/>
                                    <org.kiranahouse.component.CustomTextView
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:text="28 % Off"
                                        android:layout_alignParentRight="true"
                                        android:background="@drawable/discount_single_product"
                                        android:paddingTop="4dp"
                                        android:paddingBottom="2dp"
                                        android:paddingLeft="8dp"
                                        android:paddingRight="8dp"
                                        android:id="@+id/discount_percentage"
                                        android:layout_centerVertical="true"/>

                                </RelativeLayout>
                            </RelativeLayout>
                            <View
                                android:layout_width="match_parent"
                                android:layout_height="1dp"
                                android:background="@color/customDividerColor"/>
                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:orientation="horizontal">
                                <LinearLayout
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:orientation="horizontal"
                                    android:gravity="center"
                                    android:layout_weight="1"
                                    android:paddingTop="8dp"
                                    android:paddingBottom="8dp">
                                    <ImageView
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:scaleX="-1"
                                        android:layout_gravity="center_vertical"
                                        android:src="@drawable/ic_reply"
                                        android:tint="@color/dividerColor"
                                        android:layout_marginRight="4dp"/>
                                    <org.kiranahouse.component.CustomTextView
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:text="Share"
                                        android:textAppearance="?android:attr/textAppearanceSmall"/>
                                </LinearLayout>
                                <View
                                    android:layout_width="1sp"
                                    android:layout_height="match_parent"
                                    android:background="@color/customDividerColor"/>
                                <LinearLayout
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:orientation="horizontal"
                                    android:gravity="center"
                                    android:layout_weight="1"
                                    android:paddingTop="8dp"
                                    android:paddingBottom="8dp">
                                    <ImageView
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:scaleX="-1"
                                        android:layout_gravity="center_vertical"
                                        android:src="@drawable/ic_favorite"
                                        android:tint="@color/dividerColor"
                                        android:layout_marginRight="4dp"/>
                                    <org.kiranahouse.component.CustomTextView
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:text="Wishlist"
                                        android:textAppearance="?android:attr/textAppearanceSmall"/>
                                </LinearLayout>
                            </LinearLayout>
                        </LinearLayout>

                    </android.support.v7.widget.CardView>

                    <android.support.v7.widget.CardView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="8dp"
                        android:elevation="4dp"
                        app:cardCornerRadius="2dp">
                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:padding="16dp"
                            android:orientation="vertical">
                            <org.kiranahouse.component.CustomTextView
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:text="Unit"
                                android:textColor="@color/secondaryTextColor"/>
                            <android.support.v7.widget.RecyclerView
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginTop="8dp">

                            </android.support.v7.widget.RecyclerView>
                        </LinearLayout>

                    </android.support.v7.widget.CardView>
                    <android.support.v7.widget.CardView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="8dp"
                        android:elevation="4dp"
                        app:cardCornerRadius="2dp">
                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:orientation="vertical"
                            android:padding="16dp">
                            <android.support.v7.widget.RecyclerView
                                android:layout_width="match_parent"
                                android:layout_height="600dp">

                            </android.support.v7.widget.RecyclerView>
                        </LinearLayout>
                    </android.support.v7.widget.CardView>
                </LinearLayout>

            </LinearLayout>
        </android.support.v4.widget.NestedScrollView>
        <org.kiranahouse.component.CustomButton
            android:layout_width="match_parent"
            android:layout_height="48dp"
            app:radius="0"
            app:startColor="@color/normalButtonGradientStart"
            app:endColor="@color/normalButtonGradientEnd"
            android:text="Add to Cart"
            android:gravity="center"
            android:elevation="20dp"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:layout_alignParentBottom="true"/>
    </RelativeLayout>
</android.support.design.widget.CoordinatorLayout>

这是我拍摄的屏幕截图: 图片描述 图片描述 图片描述

图片和产品卡片视图彼此独立吗?这意味着如果您滚动产品卡片视图,上面的图片不应更改/滑动?我是正确的吗? - iMDroid
@iMDroid 是的,嵌套滚动视图和ViewPager都是独立的。我只想在滚动时隐藏ViewPager,并且如果用户通过ViewPager滑动,则应更改图像。如果我不放置“nestedscrollview”,则ViewPager在滑动时更改图像;如果我放置“nestedscrollview”,则它会在ViewPager上滚动,但我失去了对ViewPager滑动的控制。 - Vighanesh Gursale
2个回答

4

您的ViewPager没有工作是因为它没有接收到任何触摸事件,因为它在包含NestedScrollView的RelativeLayout后面。因此,更好的选择是重新设计布局。例如,在FrameLayout中添加两个RelativeLayout,并设置剪切参数。请查看下面给出的代码。我已经检查过它,如预期地工作。

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.kiranahouse.activity.SingleProductActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay"
    app:elevation="0dp">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/colorPrimary"
        app:collapseIcon="@drawable/back_colored"
        app:contentInsetLeft="0dp"
        app:contentInsetStart="0dp"
        app:contentInsetStartWithNavigation="0dp"
        app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:orientation="vertical">

        <android.support.v4.view.ViewPager
            android:id="@+id/product_image_pager"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_marginTop="60dp" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="24dp"
            android:layout_below="@+id/product_image_pager">

            <android.support.design.widget.TabLayout
                android:id="@+id/pager_tab_layout"
                android:layout_width="match_parent"
                android:layout_height="24dp"
                app:tabBackground="@drawable/tab_selector"
                app:tabGravity="center"
                app:tabIndicatorHeight="0dp" />
        </LinearLayout>
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="top"
        android:clipChildren="false"
        android:clipToPadding="false"
        android:paddingTop="250dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <android.support.v4.widget.NestedScrollView
            android:id="@+id/nestedScroll"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="56dp"
            android:elevation="12dp"
            android:scrollbars="vertical">

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

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="#fafafa"
                    android:orientation="vertical">

                    <android.support.v7.widget.CardView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:elevation="4dp"
                        app:cardCornerRadius="2dp">

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

                            <RelativeLayout
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:padding="16dp">

                                <org.kiranahouse.component.CustomTextView
                                    android:id="@+id/product_title"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:ellipsize="end"
                                    android:text="Product Name"
                                    android:textAppearance="?android:attr/textAppearanceMedium"
                                    android:textColor="@color/normalButtonGradientEnd" />

                                <RelativeLayout
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:layout_below="@+id/product_title"
                                    android:layout_marginTop="8dp">

                                    <org.kiranahouse.component.CustomTextView
                                        android:id="@+id/actual_price"
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:layout_alignParentLeft="true"
                                        android:layout_centerVertical="true"
                                        android:ellipsize="end"
                                        android:text="Rs. 1024"
                                        android:textAppearance="?android:attr/textAppearanceLarge"
                                        android:textColor="@color/primaryTextColor" />

                                    <org.kiranahouse.component.CustomTextView
                                        android:id="@+id/old_price"
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:layout_centerVertical="true"
                                        android:layout_marginLeft="16dp"
                                        android:layout_toRightOf="@+id/actual_price"
                                        android:text="Rs. 2999" />

                                    <org.kiranahouse.component.CustomTextView
                                        android:id="@+id/discount_percentage"
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:layout_alignParentRight="true"
                                        android:layout_centerVertical="true"
                                        android:background="@drawable/discount_single_product"
                                        android:paddingBottom="2dp"
                                        android:paddingLeft="8dp"
                                        android:paddingRight="8dp"
                                        android:paddingTop="4dp"
                                        android:text="28 % Off" />

                                </RelativeLayout>
                            </RelativeLayout>

                            <View
                                android:layout_width="match_parent"
                                android:layout_height="1dp"
                                android:background="@color/customDividerColor" />

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

                                <LinearLayout
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_weight="1"
                                    android:gravity="center"
                                    android:orientation="horizontal"
                                    android:paddingBottom="8dp"
                                    android:paddingTop="8dp">

                                    <ImageView
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:layout_gravity="center_vertical"
                                        android:layout_marginRight="4dp"
                                        android:scaleX="-1"
                                        android:src="@drawable/ic_reply"
                                        android:tint="@color/dividerColor" />

                                    <org.kiranahouse.component.CustomTextView
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:text="Share"
                                        android:textAppearance="?android:attr/textAppearanceSmall" />
                                </LinearLayout>

                                <View
                                    android:layout_width="1sp"
                                    android:layout_height="match_parent"
                                    android:background="@color/customDividerColor" />

                                <LinearLayout
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_weight="1"
                                    android:gravity="center"
                                    android:orientation="horizontal"
                                    android:paddingBottom="8dp"
                                    android:paddingTop="8dp">

                                    <ImageView
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:layout_gravity="center_vertical"
                                        android:layout_marginRight="4dp"
                                        android:scaleX="-1"
                                        android:src="@drawable/ic_favorite"
                                        android:tint="@color/dividerColor" />

                                    <org.kiranahouse.component.CustomTextView
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:text="Wishlist"
                                        android:textAppearance="?android:attr/textAppearanceSmall" />
                                </LinearLayout>
                            </LinearLayout>
                        </LinearLayout>

                    </android.support.v7.widget.CardView>

                    <android.support.v7.widget.CardView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="8dp"
                        android:elevation="4dp"
                        app:cardCornerRadius="2dp">

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

                            <org.kiranahouse.component.CustomTextView
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:text="Unit"
                                android:textColor="@color/secondaryTextColor" />

                            <android.support.v7.widget.RecyclerView
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginTop="8dp">

                            </android.support.v7.widget.RecyclerView>
                        </LinearLayout>

                    </android.support.v7.widget.CardView>

                    <android.support.v7.widget.CardView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="8dp"
                        android:elevation="4dp"
                        app:cardCornerRadius="2dp">

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:orientation="vertical"
                            android:padding="16dp">

                            <android.support.v7.widget.RecyclerView
                                android:layout_width="match_parent"
                                android:layout_height="600dp">

                            </android.support.v7.widget.RecyclerView>
                        </LinearLayout>
                    </android.support.v7.widget.CardView>
                </LinearLayout>

            </LinearLayout>
        </android.support.v4.widget.NestedScrollView>

        <org.kiranahouse.component.CustomButton
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:layout_alignParentBottom="true"
            android:elevation="20dp"
            android:gravity="center"
            android:text="Add to Cart"
            android:textAppearance="?android:attr/textAppearanceMedium"
            app:endColor="@color/normalButtonGradientEnd"
            app:radius="0"
            app:startColor="@color/normalButtonGradientStart" />
    </RelativeLayout>

</FrameLayout>
</android.support.design.widget.CoordinatorLayout>

Mohammad,你的解决方案是有效的,但有一个问题,appbar_scrolling_view_behavior没有起作用,相对布局在工具栏上方滚动。 - Vighanesh Gursale
哦,我没有注意到,我只是在检查固定的ViewPager滑动和嵌套滚动视图在那个ViewPager上方滚动。你最好使用CollapsingToolbarLayout来实现这个。 - Zayid Mohammed

1
问题:
如上所述,您在视图页后使用了嵌套滚动视图,并将其父级设置为协调布局,这将使嵌套滚动视图堆叠在视图页上而不是线性对齐(因为它不是线性布局)。现在,给嵌套滚动视图内容添加顶部填充并使视图页在嵌套滚动视图下可见将不允许您与其交互,因为触摸交互仍然与嵌套滚动视图的透明覆盖图层重叠在视图页上。
解决方案:
实现您想要的正确方法是使用CollapsingToolbarLayout。
1.在appBarLayout中创建CollapsingToolbarlayout,在collapsing toolbar layout中包装工具栏(即将工具栏移至collapsing toolbar layout内)。
2.将您想要的视图页固定高度定义为appbar布局的高度。
3.将内容薄暮色彩定义为当折叠工具栏时您想要的工具栏颜色,而不是为工具栏提供背景颜色。
4.将包含ViewPager和TabLayout的RelativeLayout移至CollapsingToolbarLayout内,在工具栏之上。
<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="250dp"
    app:elevation="0dp"
    android:theme="@style/AppTheme.AppBarOverlay">
    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white"
        app:contentScrim="#FAFAFA"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <android.support.v4.view.ViewPager
                android:id="@+id/product_image_pager"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
            </android.support.v4.view.ViewPager>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="24dp"
                android:layout_below="@+id/product_image_pager">
                <android.support.design.widget.TabLayout
                    android:layout_width="match_parent"
                    android:layout_height="24dp"
                    android:id="@+id/pager_tab_layout"
                    app:tabIndicatorHeight="0dp"
                    app:tabGravity="center">
                </android.support.design.widget.TabLayout>
            </LinearLayout>
        </RelativeLayout>
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:theme="@style/MyActionBarTheme"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:layout_collapseMode="pin">
    </android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

或者,您可以选择将根视图设置为LinearLayout而不是CoordinatorLayout。

虽然这是实现类似于您要求的内容的唯二正确方式,但如果您要求查看器固定在后面而不是折叠,则无法与其进行交互。 在您的情况下,固定视图浏览器并在其上滚动内容没有任何意义,因为无论如何,您都会滚动整个布局而使视图浏览器被遮挡/隐藏。因此,使用上述解决方案将模拟使用固定视图浏览器和超出滚动内容来实现您想要实现的相同效果。


@Akashy Moorthy,我不理解你所说的第四点,请问你能否解释一下如何在可折叠工具栏内移动我的相对布局? - Vighanesh Gursale
请查看上面的代码片段。我希望它能够解决您的疑问。 - Akshay Moorthy
我已经尝试过可折叠的工具栏,但是我希望视图页面不要移动。根据您刚刚提供给我的代码片段,您只是给了我一个如何将viewpager添加到可折叠工具栏的示例,这不是我想要实现的。我希望viewpager不要移动。 - Vighanesh Gursale
@VighaneshGursale,我猜这个 -> https://dev59.com/Cp3ha4cB1Zd3GeqPSlJC 是你所问的,试试这个,看看是否有效,我也会找其他解决方法。 - Akshay Moorthy

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接