我有一段xml代码,其中我有一个nestedScrollView,下面是一个recyclerview,下面是一个viewpager,它有两个片段,这两个片段都包含recyclerviews
我面临的问题是,recyclerviews正在滚动,但是主布局未滚动。经过大量搜索后,我问了一个问题,但好像被卡住了。
我尝试了这些
1.只有一个子布局的scrollview
2.滚动视图的宽度和高度为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>
答案 0 :(得分: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>