CaldroidFragment的大小在ScrollView中嵌入时会混乱。原因是Caldroid使用GridView渲染日历,并且作为一个已知问题,GridView无法在ScrollView中正确测量其高度,并且迄今为止没有更好的解决方案。我尝试了一些提到的解决方法here,但到目前为止没有发现任何可行的解决办法。如何确定ScrollView中的Caldroid高度(如何确定ScrollView中嵌入的GridView的高度)
1
A
回答
1
由grennis(here)解决方案是正确的,也许只是解释它好一点:
1 .-添加您的FrameLayout的XML模板:
<FrameLayout android:id="@+id/calendar_container"
android:layout_width="match_parent"
android:layout_height="999dp" />
2:添加变量,并在您的Java活动或片段听众
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.-赋给变量日历集装箱正确的资源(可以在OnCreate或完成imilar法):
calendarContainer = (FrameLayout) getActivity().findViewById(R.id.calendar_container);
calendarContainer.getViewTreeObserver().addOnGlobalLayoutListener(CalendarViewTreeObserver);
setCustomResourceForDates();
4.-设置Caldroid片段与交易
FragmentTransaction t = getActivity().getSupportFragmentManager().beginTransaction();
t.replace(R.id.calendar_container, caldroidFragment);
t.commit();
也许一些其他方面的考虑是,这一解决办法可能只在16 API工作+由于removeOnGlobalLayoutListener和在这个例子中,我在片段内工作
0
终于找到了可行的解决方案。 gennis给出的解决方案here是正确的。我所做的唯一修改是将代码calendarContainer.getViewTreeObserver().addOnGlobalLayoutListener(CalendarViewTreeObserver)
放入CaldroidFragment的回调函数onCaldroidViewCreated
。
相关问题
- 1. 如何增加Android中的ScrollView高度?
- 2. 如何确定UITextView中行的高度?
- 3. 如何计算Android上的ScrollView内的GridView所需的高度?
- 4. 调整scrollView的高度
- 5. 如何确定InputBox的高度?
- 6. 保持ScrollView占用太高的高度
- 7. 如何确定颤动中图像的宽度和高度?
- 8. 如何确定垂直ScrollView的方向?
- 9. Android ScrollView高度太短
- 10. 如何确定电力BI报表的宽度和高度嵌入
- 11. 确定iframe的高度
- 12. 确定iFrame的高度
- 13. 确定元素的高度
- 14. 在数据绑定过程中确定GridView的高度
- 15. ScrollView中的自定义Gridview
- 16. 如何确定ul中的几个ui-btn的统一高度?
- 17. scrollView上的UIWebView调整高度
- 18. ScrollView的高度0即使fill_parent
- 19. 如何确定iOS上的实际视口宽度和高度
- 20. 如何确定字段集边框的高度和宽度?
- 21. 如何确定Android上的视频宽度和高度
- 22. 如何确定PostScript字体的高度和深度?
- 23. 如何确定UITextView中文本的高度?
- 24. 如何确定UINavigationController中工具栏的高度?
- 25. 如何确定PostScript中的字符串高度?
- 26. 如何用很多子元素获得ScrollView的高度?
- 27. 如何确定给定字体的最大像素高度?
- 28. 如何在scrollview中的dispatch_async方法中获取图像的动态高度
- 29. 如何返回正确的高度ForRowAtIndexPath
- 30. Android:如何获得准确的高度?