Reputation: 317
I have a RecyclerView in a DialogFragment. Both the Dialog fragment and recyclerview show though when the recyclerview fills beyond the view capacity it does not scroll.
?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
android:tag="FoodMenuTag"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.android.cop1803.MainActivity">
<View
android:id="@+id/divider3"
android:layout_width="1184dp"
android:layout_height="1dp"
android:layout_marginTop="@dimen/MarginTop_PDF_dividers"
android:layout_marginBottom="@dimen/MarginTop_PDF_dividers"
android:background="?android:attr/listDivider"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/kCal"
tools:layout_editor_absoluteX="8dp" />
<com.example.android.cop1803.MyRecyclerView
android:id="@+id/recycler_menuview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
app:layout_constraintTop_toBottomOf="@id/divider3"
/>
Here's my Dialog Fragment:
@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
View view = inflater.inflate(R.layout.recyclerview_menu, container, false);
mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_menuview);
return view;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Bundle args = getArguments();
if(args != null) {
cartList = args.getParcelableArrayList("key");
MenuDialogFragmentAdapter adapter = new
MenuDialogFragmentAdapter(this.getActivity(), cartList);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setAdapter(adapter);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
}
}
@Override
public void onResume() {
// Get existing layout params for the window
ViewGroup.LayoutParams params = getDialog().getWindow().getAttributes();
// Assign window properties to fill the parent
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = WindowManager.LayoutParams.MATCH_PARENT;
getDialog().getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
// Call super onResume after sizing
super.onResume();}
Any help with getting this to work is much appreciated.
thanks,
Jim
Upvotes: 0
Views: 2343
Reputation: 7641
try adding nested scrolling to the recyclerview, see if its works.
recyclerView.setNestedScrollingEnabled(true);
Upvotes: 1
Reputation: 317
It turned out I was not accounting for the full height of my recycler view. So it was actually working but the height was extending it beyond the bottom boundary. Once I made a few adjustments to the height it worked. Here's the XML that on landed on.
<com.example.android.cop1803.MyRecyclerView
android:id="@+id/recycler_menuview"
android:layout_width="match_parent"
android:layout_height="350dp"
android:layout_marginStart="8dp"
android:layout_marginBottom="8dp"
android:scrollbars="vertical"
app:layout_constraintVertical_bias="0.01"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/divider3" />
I don't like the height being a fixed value so I'll likely change via code. thanks, Jim
Upvotes: 1