包含recyclerview和viewpager的Scrollview不滚动

问题描述 投票:1回答:1

我有一段xml代码,其中我有一个nestedScrollView,下面是一个recyclerview,下面是一个viewpager,它有两个片段,这两个片段都包含recyclerviews我面临的问题是recyclerviews是滚动但主要布局不滚动。经过大量的搜索,我问这个问题,但好像我被卡住了。 我尝试了这些1. scrollview只有一个子布局2. scrollview宽度和高度为fill_parent

<RelativeLayout 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="wrap_content"
    tools:context=".homeScreen.fragments.home.baseFragment.Home">



    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/_200sdp"
        android:background="@drawable/home_screen_banner">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="@dimen/_200sdp"
            android:alpha="0.6"
            android:background="@color/colorBlack"
            android:scaleType="fitXY" />

    </RelativeLayout>

    <LinearLayout
        android:id="@+id/homeFragmentHeader"
        android:layout_width="match_parent"
        android:layout_height="@dimen/_200sdp"
        android:gravity="center_horizontal"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/_80sdp"
            android:text="Find Your Dream Job"
            android:textColor="@color/colorWhite"
            android:textSize="@dimen/_15sdp"
            android:textStyle="bold" />

        <View
            android:layout_width="@dimen/_80sdp"
            android:layout_height="@dimen/_2sdp"
            android:layout_marginTop="@dimen/_10sdp"
            android:background="@color/mainOrangeColor" />

        <LinearLayout
            android:layout_width="@dimen/_240sdp"
            android:layout_height="@dimen/_25sdp"
            android:layout_marginTop="@dimen/_20sdp"
            android:background="@drawable/edit_text_bg">

            <EditText
                android:id="@+id/homeFragmentSearchField"
                android:layout_width="@dimen/_190sdp"
                android:layout_height="@dimen/_25sdp"
                android:layout_gravity="center"
                android:layout_marginStart="@dimen/_5sdp"
                android:background="@drawable/edit_text_bg"
                android:focusedByDefault="false"
                android:hint="search keyword..."
                android:inputType="textNoSuggestions"
                android:textSize="@dimen/_10sdp" />

            <LinearLayout
                android:id="@+id/homeFragmentSearchLl"
                android:layout_width="@dimen/_40sdp"
                android:layout_height="match_parent"
                android:layout_marginStart="@dimen/_5sdp"
                android:background="@color/mainOrangeColor"
                android:gravity="center">

                <ImageView
                    android:layout_width="@dimen/_20sdp"
                    android:layout_height="@dimen/_20sdp"
                    android:layout_gravity="center"
                    android:src="@drawable/ic_search" />

            </LinearLayout>
        </LinearLayout>


    </LinearLayout>

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

        android:layout_below="@+id/homeFragmentHeader">

        <android.support.v4.widget.NestedScrollView
            android:id="@+id/nest_scrollview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:fillViewport="true">

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

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

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

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="@dimen/_10sdp"
                            android:layout_marginTop="@dimen/_20sdp"
                            android:text="Select"
                            android:textColor="@color/colorGrey"
                            android:textSize="@dimen/_12sdp"
                            android:textStyle="bold" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="@dimen/_5sdp"
                            android:layout_marginTop="@dimen/_20sdp"
                            android:text="Category"
                            android:textColor="@color/mainOrangeColor"
                            android:textSize="@dimen/_12sdp"
                            android:textStyle="bold" />
                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content">

                        <View
                            android:layout_width="@dimen/_20sdp"
                            android:layout_height="@dimen/_2sdp"
                            android:layout_marginStart="@dimen/_10sdp"
                            android:background="@color/mainOrangeColor" />
                    </LinearLayout>

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

                        <ImageView
                            android:layout_width="@dimen/_10sdp"
                            android:layout_height="@dimen/_10sdp"
                            android:layout_centerVertical="true"
                            android:layout_marginStart="@dimen/_7sdp"
                            android:elevation="@dimen/_16sdp"
                            android:src="@drawable/ic_left"
                            android:tint="@color/mainOrangeColor" />

                        <ImageView
                            android:layout_width="@dimen/_10sdp"
                            android:layout_height="@dimen/_10sdp"
                            android:layout_alignParentEnd="true"
                            android:layout_centerVertical="true"
                            android:layout_marginEnd="@dimen/_7sdp"
                            android:elevation="@dimen/_16sdp"
                            android:src="@drawable/ic_right"
                            android:tint="@color/mainOrangeColor" />

                        <android.support.v7.widget.RecyclerView
                            android:id="@+id/homeFragmentRv"
                            android:layout_width="match_parent"
                            android:layout_height="@dimen/_100sdp"
                            android:layout_marginTop="@dimen/_10sdp">

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

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

                        <android.support.design.widget.TabLayout
                            android:id="@+id/homeFragmentTabLayout"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="@dimen/_5sdp"
                            android:background="@color/colorWhite"
                            app:tabIndicatorColor="@color/mainOrangeColor"
                            app:tabIndicatorFullWidth="false"
                            app:tabSelectedTextColor="@color/mainOrangeColor"
                            app:tabTextColor="@color/colorGrey" />

                        <android.support.v4.view.ViewPager
                            android:id="@+id/homeFragmentViewPager"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content" />
                    </LinearLayout>
                </LinearLayout>

            </RelativeLayout>

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

</RelativeLayout>
android scrollview android-nestedscrollview nestedscrollview
1个回答
1
投票
 <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

    android:layout_below="@+id/homeFragmentHeader">

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/nest_scrollview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true">

RelativeLayout高度match_parent NestedScrollView高度必须是wrap_content而子ViewHroups高度必须是wrap_content

最后它应该看起来像这样

<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">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/_200sdp"
        android:background="@drawable/home_screen_banner">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="@dimen/_200sdp"
            android:alpha="0.6"
            android:background="@color/colorBlack"
            android:scaleType="fitXY"/>

    </RelativeLayout>

    <LinearLayout
        android:id="@+id/homeFragmentHeader"
        android:layout_width="match_parent"
        android:layout_height="@dimen/_200sdp"
        android:gravity="center_horizontal"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/_80sdp"
            android:text="Find Your Dream Job"
            android:textColor="@color/colorWhite"
            android:textSize="@dimen/_15sdp"
            android:textStyle="bold"/>

        <View
            android:layout_width="@dimen/_80sdp"
            android:layout_height="@dimen/_2sdp"
            android:layout_marginTop="@dimen/_10sdp"
            android:background="@color/mainOrangeColor"/>

        <LinearLayout
            android:layout_width="@dimen/_240sdp"
            android:layout_height="@dimen/_25sdp"
            android:layout_marginTop="@dimen/_20sdp"
            android:background="@drawable/edit_text_bg">

            <EditText
                android:id="@+id/homeFragmentSearchField"
                android:layout_width="@dimen/_190sdp"
                android:layout_height="@dimen/_25sdp"
                android:layout_gravity="center"
                android:layout_marginStart="@dimen/_5sdp"
                android:background="@drawable/edit_text_bg"
                android:focusedByDefault="false"
                android:hint="search keyword..."
                android:inputType="textNoSuggestions"
                android:textSize="@dimen/_10sdp"/>

            <LinearLayout
                android:id="@+id/homeFragmentSearchLl"
                android:layout_width="@dimen/_40sdp"
                android:layout_height="match_parent"
                android:layout_marginStart="@dimen/_5sdp"
                android:background="@color/mainOrangeColor"
                android:gravity="center">

                <ImageView
                    android:layout_width="@dimen/_20sdp"
                    android:layout_height="@dimen/_20sdp"
                    android:layout_gravity="center"
                    android:src="@drawable/ic_search"/>

            </LinearLayout>
        </LinearLayout>
    </LinearLayout>

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/nest_scrollview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/homeFragmentHeader">

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

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

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="@dimen/_10sdp"
                    android:layout_marginTop="@dimen/_20sdp"
                    android:text="Select"
                    android:textColor="@color/colorGrey"
                    android:textSize="@dimen/_12sdp"
                    android:textStyle="bold"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="@dimen/_5sdp"
                    android:layout_marginTop="@dimen/_20sdp"
                    android:text="Category"
                    android:textColor="@color/mainOrangeColor"
                    android:textSize="@dimen/_12sdp"
                    android:textStyle="bold"/>
            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

                <View
                    android:layout_width="@dimen/_20sdp"
                    android:layout_height="@dimen/_2sdp"
                    android:layout_marginStart="@dimen/_10sdp"
                    android:background="@color/mainOrangeColor"/>
            </LinearLayout>

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

                <ImageView
                    android:layout_width="@dimen/_10sdp"
                    android:layout_height="@dimen/_10sdp"
                    android:layout_centerVertical="true"
                    android:layout_marginStart="@dimen/_7sdp"
                    android:elevation="@dimen/_16sdp"
                    android:src="@drawable/ic_left"
                    android:tint="@color/mainOrangeColor"/>

                <ImageView
                    android:layout_width="@dimen/_10sdp"
                    android:layout_height="@dimen/_10sdp"
                    android:layout_alignParentEnd="true"
                    android:layout_centerVertical="true"
                    android:layout_marginEnd="@dimen/_7sdp"
                    android:elevation="@dimen/_16sdp"
                    android:src="@drawable/ic_right"
                    android:tint="@color/mainOrangeColor"/>

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/homeFragmentRv"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/_100sdp"
                    android:layout_marginTop="@dimen/_10sdp">

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

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

                <android.support.design.widget.TabLayout
                    android:id="@+id/homeFragmentTabLayout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="@dimen/_5sdp"
                    android:background="@color/colorWhite"
                    app:tabIndicatorColor="@color/mainOrangeColor"
                    app:tabIndicatorFullWidth="false"
                    app:tabSelectedTextColor="@color/mainOrangeColor"
                    app:tabTextColor="@color/colorGrey"/>

                <android.support.v4.view.ViewPager
                    android:id="@+id/homeFragmentViewPager"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"/>

            </LinearLayout>
        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
</RelativeLayout>
© www.soinside.com 2019 - 2024. All rights reserved.