У меня есть ScrollView
, внутри которого у меня есть ListView
, за которым следует несколько TextViews. ListView
, который у меня есть, заполняется с использованием пользовательского адаптера, а ширина элементов может варьироваться в зависимости от того, на какой странице мы находимся. Вот мой ScrollView
:Высота просмотров внутри ScrollView
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/options_listview">
</ListView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/options_listview">
<TextView
android:layout_width="match_parent"
android:layout_height="24dp"
android:text="Explanation:"
android:id="@+id/explanation_header"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/explanation_text"
android:layout_below="@+id/explanation_header"
android:text="stuff..."/>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
ПРОБЛЕМА
Высота ListView не отображается полностью. Я программно установки высоты, как:
public static void setListViewHeight(ListView list) {
int height = 0;
for (int i = 0; i < list.getCount(); i++) {
View childView = list.getAdapter().getView(i, null, list);
childView.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
height+= childView.getMeasuredHeight();
}
//dividers height
height += list.getDividerHeight() * list.getCount();
ViewGroup.LayoutParams params = list.getLayoutParams();
params.height = height;
list.setLayoutParams(params);
Log.i("Height ", height + "");
}
Теперь я вижу в журналах, что я получаю ту же высоту для всех ListViews независимо от высоты элемента. Как я могу сделать ListView полностью видимым в моем scrollview?
изменить listview высота соответствует родительскому –
не повезло с этим. –
- это прокрутка списка? Значит, у них достаточно объекта, чтобы listview мог прокручивать или покрывать все пространство? –