The size of CaldroidFragment is messed when it is embed in a ScrollView. The reason is Caldroid uses GridView to render the calendar, and as an known issue that GridView cannot correctly measure it's height correctly inside ScrollView and so far there is no better solution. And I tried some workarounds mentioned here, but so far didn't find any of them workable.
2 Answers
the solution by grennis (here)is correct, maybe just to explain it a bit better:
1.- Add your FrameLayout on the xml template:
<FrameLayout android:id="@+id/calendar_container"
android:layout_width="match_parent"
android:layout_height="999dp" />
2.- Add the variable and the listener on your Java Activity or Fragment
private ViewTreeObserver.OnGlobalLayoutListener CalendarViewTreeObserver = new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
calendarContainer.getViewTreeObserver().removeOnGlobalLayoutListener(CalendarViewTreeObserver);
ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) calendarContainer.getLayoutParams();
lp.height = ((ViewGroup)calendarContainer).getChildAt(0).getHeight();
calendarContainer.setLayoutParams(lp);
calendarContainer.requestLayout();
}
};
private FrameLayout calendarContainer;
3.- assign the proper resource to the variable calendar Container (that can be done in the onCreate or a similar method):
calendarContainer = (FrameLayout) getActivity().findViewById(R.id.calendar_container);
calendarContainer.getViewTreeObserver().addOnGlobalLayoutListener(CalendarViewTreeObserver);
setCustomResourceForDates();
4.- set the Caldroid fragment with the transaction
FragmentTransaction t = getActivity().getSupportFragmentManager().beginTransaction();
t.replace(R.id.calendar_container, caldroidFragment);
t.commit();
maybe some other considerations would be that this workaround may only work on API 16 + due to the removeOnGlobalLayoutListener and that in the example I was working inside a Fragment

- 56
- 3
Finally found the workable solution. The solution gennis gave out here is correct. The only change I made is put the code calendarContainer.getViewTreeObserver().addOnGlobalLayoutListener(CalendarViewTreeObserver)
into the call-back function onCaldroidViewCreated
of CaldroidFragment.

- 345
- 1
- 12