Ваш xml-код верен, но нуждается в некоторых изменениях, проверьте код ниже:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".SwipeRefreshLayoutActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/title_display"
android:text="@string/course_view"
android:layout_toLeftOf="@id/edit_course_button"
android:layout_toStartOf="@id/edit_course_button"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/date_display"
android:text="@string/start_and_end_dates"
android:layout_toLeftOf="@id/edit_course_button"
android:layout_toStartOf="@id/edit_course_button"
android:layout_below="@id/title_display"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/mentor_display"
android:text="@string/course_mentor_display_default"
android:layout_toLeftOf="@id/edit_course_button"
android:layout_toStartOf="@id/edit_course_button"
android:layout_below="@id/date_display"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/credits_display"
android:text="@string/course_credits_display_default"
android:layout_toLeftOf="@id/edit_course_button"
android:layout_toStartOf="@id/edit_course_button"
android:layout_below="@id/mentor_display"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/passed_display"
android:text="@string/passed"
android:textColor="#128039"
android:textStyle="bold"
android:visibility="gone"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_above="@id/separator"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/edit_course_button"
android:text="@string/edit_course"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/separator"
android:layout_below="@id/credits_display"
android:background="#333"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="match_parent"
android:layout_height="2dp" />
</RelativeLayout>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Objectives"
android:layout_centerVertical="true"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon_arrow_left"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
<ListView
android:id="@+id/list_objectives"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Assessments"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon_arrow_left"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
<ListView
android:id="@+id/list_assessments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Notes"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon_arrow_left"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
<ListView
android:id="@+id/list_notes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
К Scroll
несколько списков просмотра в представлении прокрутки добавить код ниже в файле Java:
public void setListViewHeight(ListView listView) {
ArrayAdapter listAdapter = (ArrayAdapter) listView.getAdapter();
if (listAdapter != null) {
int totalHeight = 0;
for (int i = 0; i < listAdapter.getCount(); i++) {
View listItem = listAdapter.getView(i, null, listView);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
listView.setLayoutParams(params);
listView.requestLayout();
}
}
Как вызвать вышеуказанный метод в Java-файле:
После установки adapter
на listview
метод вызова, как показано ниже:
final ListArrayAdapter adapter3 = new ListArrayAdapter(this,
android.R.layout.simple_list_item_1, arrayList3);
listAssessments.setAdapter(adapter3);
setListViewHeight(listAssessments);
Я надеюсь, что он работает длявы.