1

I have a LinearLayout and dynamically add three LinearLayouts to it. Each of the LinearLayouts contains a Button. After pressing one of the Buttons I wanted to display a CalendarView in the second-level LinearLayout. The View is displayed, however, it is not shown fully. I have attached a screenshot to visualize the problem: https://i.stack.imgur.com/CE9je.png

Here is the code for adding the layout:

LinearLayout.LayoutParams pLayouts = new LinearLayout.LayoutParams(
        LinearLayout.LayoutParams.MATCH_PARENT,
        LinearLayout.LayoutParams.WRAP_CONTENT
);
hllCalendar = new LinearLayout(this);
hllCalendar.setLayoutParams(pLayouts);
hllCalendar.setId(hllCalendarID);
hllCalendar.setOrientation(LinearLayout.VERTICAL);
btCalendar = {some other code}
hllCalendar.addView(btCalendar);
hllComponents.addView(hllCalendar);

And here is the code for adding the CalendarView:

LinearLayout.LayoutParams pCalendar = new LinearLayout.LayoutParams(
        LinearLayout.LayoutParams.MATCH_PARENT,
        LinearLayout.LayoutParams.WRAP_CONTENT
);
CalendarView cal = new CalendarView(this);
cal.setLayoutParams(pCalendar);
cal.setOnDateChangeListener(this);
hllCalendar.addView(cal);

Any suggestions on how I could make the calendar fully visible?

Here is the dynamically created layout for your convenience:

hllComponents pLayouts
-hllCalendar pLayouts
--btCalendar
--CalendarView pCalendar
-hllStartTime pLayouts
--btStartTime
-hllEndTime pLayouts
--btEndTime

The problem is the same as in this post.

Community
  • 1
  • 1
  • You would need to add the LayoutParams you set onto the neighboring linear layouts – Zaid Daghestani Jun 10 '12 at 20:04
  • @ZedScio The LayoutParams for Layouts is pLayouts as you can see in the first code section. –  Jun 11 '12 at 14:14
  • I meant the layouts surrounding hllCalendar. The most likely culprit is that hllCalendar does not have enough room to resize to wrap_content. You can test this by putting hllCalendar inside a scrollview. If you can scroll through and see the entire view, then the issue is the layouts above and/or below hllCalendar, inside hllComponents. – Zaid Daghestani Jun 11 '12 at 14:18
  • @ZedScio I have added a hierarchy to my original post for you to see my current layout. Even if I remove the second and third LinearLayout the CalendarView is still not expanded, even with Udinic's help. –  Jun 11 '12 at 14:42

1 Answers1

0

Try calling the requestLayout() of the parent layout.

This will post a "relayout" message on the UI's messages loop. This will calculate the new size of the layout, after the calendar was added, and thus paint it fully on the screen.

Udinic
  • 3,014
  • 2
  • 25
  • 32
  • Unfortunatly that did not work out. I added these lines to the second snippet: `hllCalendar.addView(cal);hllCalendar.requestLayout(); hllComponents.requestLayout();` –  Jun 11 '12 at 14:26