I have an activity which contains text and a fragment:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
tools:context="bla.HomeActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="A Text"
android:id="@+id/home_text_view"/>
<fragment
android:name="bla.CalendarAgendaFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cf"
tools:layout="@layout/fragment_calendar_agenda" />
</LinearLayout>
</ScrollView>
</LinearLayout>
The fragment only contains a ListView which is filled dynamically:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/calendar_agenda_listview"
android:layout_gravity="center_horizontal" />
</LinearLayout>
The onCreateView method of the fragment looks like this:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_calendar_agenda, container, false);
agenda_dates = new ArrayList<CalendarDate>();
agenda_dates.add(new CalendarDate("10.10.2015", "Kuchen backen"));
agenda_dates.add(new CalendarDate("10.10.2015", "Fenster putzen"));
list = (ListView) v.findViewById(R.id.calendar_agenda_listview);
adapter = new AgendaAdapter(getActivity(), R.layout.calendar_agenda_listview_item, agenda_dates);
list.setAdapter(adapter);
return v;
}
The code works and both CalendarDates are added to the fragment.
The problem is that the fragment is only about 40dp high and so only the first ListView item is shown. I can only see the second item by inline scrolling inside of the list view. How can I set the fragment's hight according to it's content?