Cómo implementar un ListView completamente dentro de un ScrollView
Aquí, estoy usando un listView
dentro de un ScrollView
, todo está funcionando bien, pero listView
no se muestra completamente cuando establezco su altura fill_parent
. Así que he fijado su altura y no se ve bien cuando cambio el dispositivo de teléfono Android. ¿Puede alguien ayudarme en ella? Estoy publicando mi clase de xml también.
Demo.xml
- Establecer la altura de la fila ListView en el código
- Desmarca todas las casillas de verificación en un ListView personalizado
- CheckBox Hacer la listaNo se puede hacer clic en el elemento
- Cómo obtener una posición de elemento de lista haciendo clic en el botón dentro de él?
- cómo agregar varias vistas de imagen en la fila de vista de lista con vista de desplazamiento horizontal
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginTop="25dp" android:gravity="center" android:orientation="vertical" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:paddingLeft="6dp" android:text="@string/course_tracker" android:textStyle="bold" /> </LinearLayout> <LinearLayout android:id="@+id/ll_finishapp_table" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginTop="10dp" android:orientation="vertical" > <View android:layout_width="match_parent" android:layout_height="2dp" android:background="#E3E3E3" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#ffffff" android:orientation="horizontal" android:weightSum="20" > <TextView android:layout_width="2dp" android:layout_height="match_parent" android:background="#E3E3E3" android:text="" /> <LinearLayout android:layout_width="0dip" android:layout_height="match_parent" android:layout_weight="5" android:orientation="vertical" > <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_horizontal|center_vertical" android:text="@string/program_name" /> </LinearLayout> <TextView android:layout_width="2dp" android:layout_height="match_parent" android:background="#E3E3E3" android:text="" /> <LinearLayout android:layout_width="0dip" android:layout_height="match_parent" android:layout_weight="2" android:gravity="center" android:orientation="vertical" android:background="#e9e9e9" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="@string/colon" android:textStyle="bold" /> </LinearLayout> <TextView android:layout_width="2dp" android:layout_height="match_parent" android:background="#E3E3E3" android:text="" /> <LinearLayout android:layout_width="0dip" android:layout_height="match_parent" android:layout_weight="13" android:gravity="center_vertical" android:orientation="vertical" > <TextView android:id="@id/tv_program_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingLeft="10dp" android:textStyle="bold" /> </LinearLayout> <TextView android:layout_width="2dp" android:layout_height="match_parent" android:background="#E3E3E3" android:text="" /> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="2dp" android:background="#E3E3E3" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#F9F9F9" android:orientation="horizontal" android:weightSum="20" > <TextView android:layout_width="2dp" android:layout_height="match_parent" android:background="#E3E3E3" android:text="" /> <LinearLayout android:layout_width="0dip" android:layout_height="match_parent" android:layout_weight="5" android:orientation="vertical" > <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_horizontal|center_vertical" android:text="@string/program_description" /> </LinearLayout> <TextView android:layout_width="2dp" android:layout_height="match_parent" android:background="#E3E3E3" android:text="" /> <LinearLayout android:layout_width="0dip" android:layout_height="match_parent" android:layout_weight="2" android:gravity="center" android:orientation="vertical" android:background="#e9e9e9" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="@string/colon" android:textStyle="bold" /> </LinearLayout> <TextView android:layout_width="2dp" android:layout_height="match_parent" android:background="#E3E3E3" android:text="" /> <LinearLayout android:layout_width="0dip" android:layout_height="match_parent" android:layout_weight="13" android:gravity="center_vertical" android:orientation="vertical" > <TextView android:id="@id/tv_program_description" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingLeft="10dp" android:textStyle="bold" /> </LinearLayout> <TextView android:layout_width="2dp" android:layout_height="match_parent" android:background="#E3E3E3" android:text="" /> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="2dp" android:background="#E3E3E3" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginTop="20dp" android:orientation="vertical" > <View android:layout_width="match_parent" android:layout_height="2dp" android:background="#E3E3E3" /> <LinearLayout android:layout_width="match_parent" android:layout_height="30dp" android:background="#ffffff" android:orientation="horizontal" android:weightSum="20" > <TextView android:layout_width="2dp" android:layout_height="match_parent" android:background="#E3E3E3" android:text="" /> <LinearLayout android:layout_width="0dip" android:layout_height="match_parent" android:layout_weight="10" android:orientation="vertical" > <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_horizontal|center_vertical" android:text="@string/course_name" /> </LinearLayout> <TextView android:layout_width="2dp" android:layout_height="match_parent" android:background="#E3E3E3" android:text="" /> <LinearLayout android:layout_width="0dip" android:layout_height="match_parent" android:layout_weight="10" android:orientation="vertical" > <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_horizontal|center_vertical" android:text="@string/semester" /> </LinearLayout> <TextView android:layout_width="2dp" android:layout_height="match_parent" android:background="#E3E3E3" android:text="" /> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="2dp" android:background="#E3E3E3" /> <ListView android:id="@id/list_course" android:layout_width="match_parent" android:layout_height="350dp" android:layout_marginBottom="10dp" > </ListView> </LinearLayout> </LinearLayout></ScrollView>
Gracias.
- SearchView con múltiples fragmentos usando viewpager en android
- ListView haga clic para mostrar la imagen en ImageView
- La posición de desplazamiento salta a los elementos de la lista anterior mientras se desplaza hacia arriba en la vista de lista personalizada
- Cómo implementar la paginación en Android listview
- Buggy ListView me hace triste
- OnClick listener a una imagen ListView - Android
- Android
- ¿Cómo hacer el desplazamiento de ListView más lento cuando se utiliza la función smoothScrollToPosition ()?
De forma dinámica establecer la altura de ListView basado en el recuento de listas, como:
private void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) { return; } int totalHeight = 0; for (int i = 0; i < listAdapter.getCount(); i++) { View listItem = listAdapter.getView(i, null, listView); if (listItem != null) { listItem.measure( MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); } totalHeight += listItem.getMeasuredHeight(); } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); listView.setLayoutParams(params); listView.requestLayout(); }
Llamada anterior método después de establecer el adaptador en el ListView, como:
urListView.setAdapter(urAdapter); setListViewHeightBasedOnChildren(urListView);
Simplemente utilice el headerView del ListView: Coloque todas las cosas que desea por encima de la lista en el headerView y todas las cosas que desea a continuación en el footerView. El listView se mostrará a toda la altura y el headerView es desplazable.
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment, container, false); mListViewHeaderView = initHeaderView(mListView, inflater); mListView = (ListView) view.findViewById(R.id.listView); mListView.addHeaderView(mListViewHeaderView, null, false); return view; } private View initHeaderView(ViewGroup container, LayoutInflater inflater) { View headerView = inflater.inflate(R.layout.fragment_atm_details_header, container, false); // configure header view return headerView; }
- Fallo de la conexión del bluetooth androide (isSocketAllowedBySecurityPolicy inicio: dispositivo nulo)
- La localización simulada no funciona en el mapa de Google