0

각 뷰에는 nestedScrollView를 사용하는 3 개의 프래그먼트가 있습니다. 하나를 전환 할 때마다 nestedScrollView가 appBar 아래로 스크롤됩니다. 필자는 InfoFragment의 수명주기 동안 특정 뷰를 설정하는 것이 문제가 될 수 있다고 생각합니다. 나는 그것을 아래에 게시 할 것이다. enter image description hereviewPager 내에서 nestedScrollView를 사용하면 이상한 동작이 발생합니다.

정보] 조각의 XML :

<android.support.v4.widget.NestedScrollView 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/scroll_view" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="72dp" 
android:clipToPadding="false" 
> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    tools:ignore="RtlSymmetry" 
    tools:targetApi="N"> 

    <TextView 
     android:id="@+id/tagline" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="16dp" 
     android:padding="16dp" 
     android:gravity="center" 
     android:textSize="18sp" 
     android:textStyle="italic|bold" 
     android:fontFamily="sans-serif-condensed" 
     tools:text="Good vs Evil" /> 

    <TextView 
     android:id="@+id/overview" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="14dp" 
     android:gravity="center" 
     android:textSize="18sp" 
     tools:text="@string/dummy_summary" 
     /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="16dp" 
     android:textSize="20sp" 
     android:textStyle="bold" 
     android:text="@string/cast"/> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/cast_list" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="16dp" 
     android:orientation="vertical" 
     android:clipToPadding="false" 
     android:nestedScrollingEnabled="false" 
     app:layoutManager="LinearLayoutManager" 
     tools:listitem="@layout/card_actor" 
     tools:layout_height="200dp"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="16dp" 
     android:textSize="20sp" 
     android:textStyle="bold" 
     android:text="@string/where_to_watch"/> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/source_list" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="16dp" 
     android:orientation="vertical" 
     android:clipToPadding="false" 
     android:nestedScrollingEnabled="false" 
     app:layoutManager="LinearLayoutManager" 
     tools:listitem="@layout/card_source" /> 
</LinearLayout> 

viewPager를 포함하는 조각에서 XML :

<FrameLayout 
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" 
app:layout_behavior="@string/appbar_scrolling_view_behavior" 
tools:targetApi="lollipop"> 

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

<android.support.v4.widget.ContentLoadingProgressBar 
    android:id="@+id/loading" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    style="?android:progressBarStyle" 
    tools:targetApi="lollipop" /> 

<RelativeLayout 
    android:id="@+id/error" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center"> 

    <TextView 
     android:id="@+id/error_message" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:padding="32dp" 
     /> 

    <Button 
     android:id="@+id/error_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/error_message" 
     android:layout_centerHorizontal="true" 
     android:text="@string/recycle"/> 
</RelativeLayout> 

InfoFragment. UpdateView()는 모든 onStart()에서 발표자의 하위보기에 자신을 추가 할 때마다 호출됩니다.

class MovieInfoFragment() : BaseFragment(), MovieContract.Subview { 
// Parameters 
override val layoutId: Int = R.layout.fragment_movie_info 

// Objects 
@Inject lateinit var presenter: MovieContract.Presenter 
@Inject lateinit var creditsAdapter: CreditsAdapter 
@Inject lateinit var sourceAdapter: SourceAdapter 

// Views 
val overview: TextView get() = find(R.id.overview) 
val tagline: TextView get() = find(R.id.tagline) 
val castList: RecyclerView get() = find(R.id.cast_list) 
val sourceList: RecyclerView get() = find(R.id.source_list) 

fun updateView() { 
    if (view == null || activity == null) return 
    presenter.getMovie()?.let { 
     overview.text = " ${it.overview}" 
     tagline.text = it.tagline 
     tagline.visibleIf(!it.tagline.isNullOrBlank()) 
     creditsAdapter.credits = it.credits 
     sourceAdapter.setNewItems(it.sources) 
    } 
} 

override fun updateMovie(movie: Movie) { 
    updateView() 
} 

override fun updateColor(color: Int) { 

} 

override fun scrollToTop() { 

} 

override fun onViewCreated(view: View?, savedInstanceState: Bundle?) { 
    super.onViewCreated(view, savedInstanceState) 
    castList.adapter = creditsAdapter 
    sourceList.adapter = sourceAdapter 
    sourceAdapter.listener = { presenter.onSourceClicked(it) } 
} 

override fun onStart() { 
    super.onStart() 
    presenter.addSubview(this) 
} 

override fun onStop() { 
    presenter.removeSubview(this) 
    super.onStop() 
} 

}

답변

0

내 생각 엔 데이터가로드 또는 어댑터에 업데이트 될 때 recycleview가 포커스를 요구하기 때문이다. 해결책으로 다음을 추가하십시오. android:descendantFocusability="blocksDescendants" 또는 yourRecycleView.setDescendantFocusability(RecyclerView.FOCUS_BLOCK_DESCENDANTS);