我有一个自定义ScrollView的布局,可以关闭。有一些片段加载到此ScrollView中。
今天,我将RecycleView添加到新的片段中,并注意到一个奇怪的行为。当RecycleView拥有android:height="match_parent"时,它会在ScrollView中扩展到完全高度。
有没有办法禁用这个功能(我想让RecycleView在内部滚动,并设置为screen_height大小)?
主要内容xml (位于CoordinatorLayout内部)
<xxx.SwitchableScrollView
android:id="@+id/main_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:id="@+id/fragment_holder"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="ScrollViewSize"/>
</xxx.SwitchableScrollView>片段布局:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/appeals_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="visible"/>
<LinearLayout
android:id="@+id/loading_progress"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ProgressBar
android:layout_width="@dimen/big_progress_diameter"
android:layout_height="@dimen/big_progress_diameter"
android:indeterminate="true"
android:indeterminateDrawable="@drawable/custom_progress_bar_primary"/>
</LinearLayout>
</FrameLayout>扩展ScrollView:
public class SwitchableScrollView extends ScrollView {
boolean allowScroll = true;
public boolean isAllowScroll() {
return allowScroll;
}
public void setAllowScroll(boolean allowScroll) {
this.allowScroll = allowScroll;
}
// .... constructors skipped
@Override
public boolean onTouchEvent(MotionEvent ev) {
return allowScroll && super.onTouchEvent(ev);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return allowScroll && super.onInterceptTouchEvent(ev);
}
}RecycleView初始化:
listView = (NestedRecyclerView) v.findViewById(R.id.appeals_list);
listView.setHorizontalScrollBarEnabled(false);
listView.setVerticalScrollBarEnabled(true);
listView.setNestedScrollingEnabled(true);
adapter = new AppealListAdapter(appealList);
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
listView.setLayoutManager(layoutManager);
listView.setAdapter(adapter);
new GetAppeals().execute();我使用的是支持库23.2.1 (也尝试了23.2.0)。ListView和GridView在另一个片段中工作得很好。
发布于 2016-03-18 21:46:53
我终于找到了答案。我花了6个小时(!)要将这一行添加到代码中:
layoutManager.setAutoMeasureEnabled(false);他们应该是疯了才会默认启用这样的东西...
https://stackoverflow.com/questions/36084565
复制相似问题