ViewPager内的ScrollView-如何滚动父布局

时间:2017-07-20 12:14:19

标签: android android-fragments android-viewpager

我有ViewPager: -

    <?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:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/white_color">

    <include
        android:id="@+id/includeLayout"
        layout="@layout/toolbar_main_user_pic" />

   <!-- <android.support.v4.widget.NestedScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone">-->

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_above="@+id/footer"
            android:layout_below="@+id/includeLayout">

            <android.support.design.widget.CoordinatorLayout
                android:id="@+id/coordinator_layout"
                android:layout_width="match_parent"
                android:layout_height="@dimen/_180sdp">

                <RelativeLayout
                    android:id="@+id/rr"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/_150sdp"
                    android:background="#000000">


                    <ImageView
                        android:id="@+id/img_bg"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/_150sdp"
                        android:alpha="0.6"
                        android:scaleType="centerCrop"
                        android:src="@drawable/car_img" />


                    <TextView
                        android:id="@+id/txt_name"
                        style="@style/Textview_red_11sp_bold"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentBottom="true"
                        android:layout_marginBottom="@dimen/_5sdp"
                        android:layout_marginLeft="@dimen/_100sdp"
                        android:text="@string/deafult_user_name"
                        android:textColor="@color/white_color" />


                    <Button
                        style="@style/ButtonBackground"
                        android:layout_alignParentBottom="true"
                        android:layout_alignParentRight="true"
                        android:layout_marginBottom="@dimen/_10sdp"
                        android:layout_marginRight="@dimen/_10sdp"
                        android:minHeight="0dp"
                        android:padding="@dimen/_5sdp"
                        android:text="@string/partecipate" />


                </RelativeLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    android:layout_marginBottom="@dimen/_5sdp"
                    android:layout_marginLeft="@dimen/_90sdp"
                    android:orientation="horizontal"
                    android:weightSum="3">

                    <LinearLayout
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:orientation="horizontal">

                        <ImageView
                            android:layout_width="@dimen/_18sdp"
                            android:layout_height="@dimen/_18sdp"
                            android:src="@mipmap/web" />

                        <TextView
                            style="@style/Textview_darkgray_11sp"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:layout_marginLeft="@dimen/_5sdp"
                            android:text="@string/public_text" />

                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:orientation="horizontal">

                        <ImageView
                            android:layout_width="@dimen/_18sdp"
                            android:layout_height="@dimen/_18sdp"
                            android:src="@mipmap/approved" />

                        <TextView
                            style="@style/Textview_darkgray_11sp"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:layout_marginLeft="@dimen/_5sdp"
                            android:text="@string/approved"
                            android:textSize="@dimen/_10sdp" />

                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="@dimen/_5sdp"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:orientation="horizontal">

                        <ImageView
                            android:layout_width="@dimen/_18sdp"
                            android:layout_height="@dimen/_18sdp"
                            android:src="@mipmap/shareimage" />

                        <TextView
                            style="@style/Textview_darkgray_11sp"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:layout_marginLeft="@dimen/_5sdp"
                            android:text="@string/share" />

                    </LinearLayout>

                </LinearLayout>

                <de.hdodenhof.circleimageview.CircleImageView
                    android:id="@+id/user_icon"
                    android:layout_width="@dimen/_70sdp"
                    android:layout_height="@dimen/_70sdp"
                    android:layout_marginLeft="@dimen/_15sdp"
                    android:src="@mipmap/profile_default"
                    app:civ_border_color="@color/gray_background_color"
                    app:civ_border_overlay="true"
                    app:civ_border_width="@dimen/_5sdp"
                    app:layout_anchor="@+id/img_bg"
                    app:layout_anchorGravity="bottom" />


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

            <View
                android:id="@+id/view"
                android:layout_width="match_parent"
                android:layout_height="@dimen/_2sdp"
                android:background="@color/gray_background_color" />

            <android.support.design.widget.TabLayout
                android:id="@+id/tab_host"
                style="@style/Tablayout_style" />

            <android.support.v4.view.ViewPager
                android:id="@+id/viewpager"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_behavior="@string/appbar_scrolling_view_behavior" />

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

    <LinearLayout
        android:id="@+id/footer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">

        <include layout="@layout/bottom_menu_layout" />
    </LinearLayout>


    <!--</LinearLayout>-->

</RelativeLayout>

这里是我的viewpager片段布局: -

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/_10sdp"
            android:background="@color/white_color"
            android:orientation="vertical"
            android:paddingLeft="@dimen/_10sdp"
            android:layout_marginBottom="@dimen/_10sdp">

            <!--<include
                layout="@layout/community_fragment_event_moreinfo"></include>-->


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

                <ImageView
                    android:id="@+id/img_cal_icon"
                    android:layout_width="@dimen/_15sdp"
                    android:layout_height="@dimen/_15sdp"
                    android:src="@mipmap/timesmall" />

                <TextView
                    android:id="@+id/txt_date"
                    style="@style/Textview_darkgray_11sp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/_5sdp"
                    android:layout_toRightOf="@+id/img_cal_icon"
                    android:text="31 November - 02 December" />

                <TextView
                    android:id="@+id/txt_date_details"
                    style="@style/Textview_gray_11sp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/txt_date"
                    android:layout_marginLeft="@dimen/_5sdp"
                    android:layout_toRightOf="@+id/img_cal_icon"
                    android:text="@string/from_december_to_december" />


            </RelativeLayout>


            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/_10sdp">

                <ImageView
                    android:id="@+id/img_location_icon"
                    android:layout_width="@dimen/_15sdp"
                    android:layout_height="@dimen/_15sdp"
                    android:src="@mipmap/location" />

                <TextView
                    android:id="@+id/txt_circuit"
                    style="@style/Textview_darkgray_11sp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/_5sdp"
                    android:layout_toRightOf="@+id/img_location_icon"
                    android:text="@string/sepang_international_circuit" />

                <TextView
                    android:id="@+id/txt_circuit_details"
                    style="@style/Textview_gray_11sp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/txt_circuit"
                    android:layout_marginLeft="@dimen/_5sdp"
                    android:layout_toRightOf="@+id/img_location_icon"
                    android:text="@string/sepang_circuit_details" />


            </RelativeLayout>

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/_10sdp">


                <ImageView
                    android:id="@+id/img_group_icon"
                    android:layout_width="@dimen/_15sdp"
                    android:layout_height="@dimen/_15sdp"
                    android:src="@drawable/group_gray" />

                <TextView
                    android:id="@+id/txt_group"
                    style="@style/Textview_darkgray_11sp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/_5sdp"
                    android:layout_toRightOf="@+id/img_group_icon"
                    android:text="@string/pilots" />

                <TextView
                    android:id="@+id/txt_pilots_count"
                    style="@style/Textview_red_11sp_bold"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/_5sdp"
                    android:layout_toRightOf="@+id/txt_group"
                    android:text="231" />

                <TextView
                    android:id="@+id/txt_dets"
                    style="@style/Textview_darkgray_11sp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_toRightOf="@+id/txt_pilots_count"
                    android:text="@string/dets" />

                <TextView
                    android:id="@+id/txt_friends"
                    style="@style/Textview_darkgray_11sp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_toRightOf="@+id/txt_dets"
                    android:text="@string/friends_dets" />

                <TextView
                    android:id="@+id/txt_friends_count"
                    style="@style/Textview_red_11sp_bold"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/_5sdp"
                    android:layout_toRightOf="@+id/txt_friends"
                    android:text="4" />

                <TextView
                    android:id="@+id/txt_friends_out_of"
                    style="@style/Textview_darkgray_11sp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_toRightOf="@+id/txt_friends_count"
                    android:text="/231" />

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/recycler_view"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/txt_group"
                    android:layout_marginLeft="@dimen/_5sdp"
                    android:layout_marginTop="@dimen/_5sdp"
                    android:layout_toRightOf="@+id/img_group_icon" />


            </RelativeLayout>

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/_10sdp">

                <ImageView
                    android:id="@+id/img_organized_icon"
                    android:layout_width="@dimen/_15sdp"
                    android:layout_height="@dimen/_15sdp"
                    android:src="@mipmap/organized" />

                <TextView
                    android:id="@+id/txt_organized"
                    style="@style/Textview_darkgray_11sp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/_5sdp"
                    android:layout_toRightOf="@+id/img_organized_icon"
                    android:text="@string/organized_by" />

                <TextView
                    android:id="@+id/txt_car_name"
                    style="@style/Textview_red_11sp_bold"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/txt_organized"
                    android:layout_marginLeft="@dimen/_5sdp"
                    android:layout_toRightOf="@+id/img_organized_icon"
                    android:text="@string/lambnorghini" />

                <TextView
                    android:id="@+id/txt_club_name"
                    style="@style/Textview_gray_11sp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/txt_car_name"
                    android:layout_marginLeft="@dimen/_5sdp"
                    android:layout_toRightOf="@+id/img_organized_icon"
                    android:text="@string/officials_valentino_rossis_club" />

            </RelativeLayout>

            <RelativeLayout
                android:id="@+id/rr_dollor_amt"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/_10sdp">

                <ImageView
                    android:id="@+id/img_dollor_icon"
                    android:layout_width="@dimen/_15sdp"
                    android:layout_height="@dimen/_15sdp"
                    android:src="@mipmap/price" />

                <TextView
                    style="@style/Textview_darkgray_11sp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="@dimen/_5sdp"
                    android:layout_toRightOf="@+id/img_dollor_icon"
                    android:text="@string/dollor_amt" />


            </RelativeLayout>

            <View
                android:id="@+id/view"
                android:layout_width="match_parent"
                android:layout_height="@dimen/_2sdp"
                android:layout_marginTop="@dimen/_5sdp"
                android:background="@color/gray_background_color" />

            <TextView
                style="@style/Textview_darkgray_11sp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/_10sdp"
                android:text="@string/details" />

            <TextView
                style="@style/Textview_gray_11sp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/lorem_ipsum" />

        <!--    <LinearLayout
                android:id="@+id/add_post_info_ll"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/_10sdp"
                android:background="@color/gray_background_color"
                android:orientation="horizontal">

                <de.hdodenhof.circleimageview.CircleImageView
                    android:id="@+id/user_profile_img"
                    android:layout_width="@dimen/_50sdp"
                    android:layout_height="@dimen/_50sdp"
                    android:src="@mipmap/profile_default" />

                <EditText
                    android:id="@+id/post_edittext"
                    style="@style/Textview_gray_11sp"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/_10sdp"
                    android:gravity="top|left"
                    android:hint="@string/whats_happening_right"
                    android:lines="3" />

            </LinearLayout>

            <RelativeLayout
                android:id="@+id/add_post_ll"
                android:layout_width="match_parent"
                android:layout_height="@dimen/_30sdp"
                android:layout_below="@+id/add_post_info_ll"
                android:background="@color/white_color"
                android:gravity="center|left"
                android:layout_marginBottom="@dimen/_10sdp"
                android:padding="@dimen/_5sdp">

                <ImageView
                    android:id="@+id/flag_icon"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_centerVertical="true"
                    android:padding="@dimen/_5sdp"
                    android:src="@mipmap/flag" />

                <ImageView
                    android:id="@+id/car_icon"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_centerVertical="true"
                    android:layout_toRightOf="@+id/flag_icon"
                    android:padding="@dimen/_5sdp"
                    android:src="@mipmap/car" />

                <ImageView
                    android:id="@+id/trophy_icon"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_centerVertical="true"
                    android:layout_toRightOf="@+id/car_icon"
                    android:padding="@dimen/_5sdp"
                    android:src="@mipmap/trophy" />

                <ImageView
                    android:id="@+id/timer_icon"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_centerVertical="true"
                    android:layout_toRightOf="@+id/trophy_icon"
                    android:padding="@dimen/_5sdp"
                    android:src="@mipmap/timer" />

                <ImageView
                    android:id="@+id/sun_icon"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_centerVertical="true"
                    android:layout_toRightOf="@+id/timer_icon"
                    android:padding="@dimen/_5sdp"
                    android:src="@mipmap/sun" />

                <ImageView
                    android:id="@+id/gallery_icon"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_centerVertical="true"
                    android:layout_toRightOf="@+id/sun_icon"
                    android:padding="@dimen/_5sdp"
                    android:src="@mipmap/gallery" />

                <ImageView
                    android:id="@+id/smiley_icon"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_centerVertical="true"
                    android:layout_toRightOf="@+id/gallery_icon"
                    android:padding="@dimen/_5sdp"
                    android:src="@mipmap/amiley" />

                <TextView
                    android:id="@+id/post_tv"
                    style="@style/Textview_white_11sp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_marginRight="@dimen/_10sdp"
                    android:background="@drawable/button_back"
                    android:paddingBottom="@dimen/_3sdp"
                    android:paddingLeft="@dimen/_10sdp"
                    android:paddingRight="@dimen/_10sdp"
                    android:paddingTop="@dimen/_3sdp"
                    android:text="@string/post" />

            </RelativeLayout>-->


        </LinearLayout>

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

</LinearLayout>

[![] [1] [1]

我想在viewpager内容滚动时滚动标题。我尝试在两个屏幕上使用嵌套ScrollView但没有取得任何成功。任何人都可以帮我解决这个问题。提前谢谢。

0 个答案:

没有答案