【发布时间】:2015-09-07 23:17:35
【问题描述】:
RecyclerView 内的ScrollView
子元素由适配器插入,回收器被分割,第三个子元素是滚动视图,但它必须在放置第一个和第二个子元素后的剩余空间中滚动。
我需要在不禁用scrollview的情况下禁用recyclerview滚动
回收容器
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/Lightgrey"
tools:context="com.inhousecrew.nocturnalkey.fragments.NightDetailsFragment">
<android.support.v7.widget.RecyclerView
android:id="@+id/nightlife_detailsrecycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="never"
android:background="@color/Background"
/>
</RelativeLayout>
这些是滚动视图容器(recyclerview 的第三个孩子)的 XML 初始属性
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="220dp"
android:layout_gravity="bottom"
android:id="@+id/scroll_details"
android:background="@color/Lightgrey">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="false">
</ScrollView>
</FrameLayout>
最后这是包含回收器的 java 类,出于逻辑目的,我使用适配器来更改第一个孩子中的数据,这就是我使用 recyclerview 的原因(首先)
public class NightDetailsFragment extends Fragment {
private RecyclerView mRecyclerNight;
private NightDetailsAdapter mAdapter;
private OnFragmentInteractionListener mListener;
public static NightlifeFragment newInstance() {
NightlifeFragment fragment = new NightlifeFragment();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
}
public NightDetailsFragment() {
}
public List<Information> getData() {
//load only static data inside a drawer
List<com.inhousecrew.nocturnalkey.fragments.Information> data = new ArrayList<>();
int icons = R.drawable.settings_w;
String titles = "Settings";
int background = R.drawable.background_user;
com.inhousecrew.nocturnalkey.fragments.Information information = new com.inhousecrew.nocturnalkey.fragments.Information();
information.title = titles;
information.iconId = icons;
information.backgroundId = background;
if(titles.equals("Profile")){
information.nightlife_active = getResources().getColor(R.color.inactive_event);
}else{
information.nightlife_active = getResources().getColor(R.color.Yellow);
}
data.add(information);
return data;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_night_details, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
mRecyclerNight = (RecyclerView) view.findViewById(R.id.nightlife_detailsrecycler);
mAdapter = new NightDetailsAdapter(getActivity() ,getData());
mRecyclerNight.setAdapter(mAdapter);
mRecyclerNight.setLayoutManager(new LinearLayoutManager(getActivity()));
}
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mListener = (OnFragmentInteractionListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnFragmentInteractionListener");
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
public interface OnFragmentInteractionListener {
public void onFragmentInteraction(Uri uri);
}
}
【问题讨论】:
-
如果你希望前两个项目的大小是固定的,而不是随着其余的滚动(以确保剩余的项目只占用剩余的空间),为什么它们甚至在
RecyclerView作为RecyclerView上方的固定元素? -
因为当我设置包含回收器的布局时,即使将高度设置为小于屏幕尺寸(垂直),它也只会显示回收器,它只会忽略除回收器之外的所有视图
-
这是一个完全不同的问题:发布显示问题的布局文件,也许我们可以帮助您解决根本问题
标签: android uiscrollview scrollview android-recyclerview