Android ListActivity – encabezado fijo y pie de página
¿Es posible establecer el encabezado y el pie de página en ListActivity para que se fijen en la parte superior e inferior, por lo que sólo el contenido (lista) se desplaza, no también el encabezado y el pie de página?
He fijado ambos como esto:
- Android gridview cabeza solución con el adaptador de reciclaje de células
- Android Api 23 Cambiar Navegación Ver headerLayout textview
- ¿Es posible incluir encabezados http en una solicitud de Google Docs?
- ¿Es posible desplazarse y pegar como una cabecera cuando llega a la parte superior de la pantalla en android?
- Android restlet añadir no estándar de encabezado param
View header = getLayoutInflater().inflate(R.layout.list_header, null); View footer = getLayoutInflater().inflate(R.layout.list_footer, null); ListView listView = getListView(); listView.addHeaderView(header); listView.addFooterView(footer);
- ¿Hay una buena razón para que un encabezado ListView ocupe una posición?
- El mejor lugar para añadirHeaderView en ListFragment
- Android - Categorías de encabezados en PreferenceActivity con PreferenceFragment
- ¿Cómo puedo hacer encabezados pegajosos en RecyclerView? (Sin librería externa)
- ¿Cómo puedo crear una barra de botones de encabezado o pie de página para mi aplicación de Android?
- Android AsyncHttpClient, no se puede encontrar la clase de símbolo Header
- ¿Cómo configurar Header, Scrollable content y Footer? en Android
- Android: headerDividersEnabled no funciona
Puede lograrlo utilizando un diseño XML personalizado en el que establecerá el diseño de su encabezado, pie de página y lista.
Tenga en cuenta que para ser compatible con ListActivity
este diseño debe contener un ListView
con el id android.R.id.list
:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="HEADER" /> <ListView android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="FOOTER" /> </LinearLayout>
Y establecerlo en su ListActivity
como este:
public class TestActivity extends ListActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }
Según el escenario del proyecto, esta metodología sería mejor que cualquier otro enfoque, ya que si desea personalizar el encabezado y el pie de página, puede realizar cambios en el diseño de encabezado y pie de página adecuado. En su archivo xml de diseño, siga lo siguiente:
En main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <include android:id="@+id/header_layout" android:layout_width="fill_parent" android:layout_height="wrap_content" layout="@layout/header.xml" /> <ListView android:id="@+id/list_view" android:layout_width="fill_parent" android:layout_height="wrap_content" android:below="@id/header_layout" android:above="@id/footer_layout" /> <include android:id="@+id/footer_layout" android:layout_width="fill_parent" android:layout_height="wrap_content" layout="@layout/footer.xml" /> </RelativeLayout>
En header.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/header_text_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Your Application Title"/> </LinearLayout>
En footer.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:id="@+id/done_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Done"/> </LinearLayout>
En Actividad, Aquí
public class MainActivity extends ListActivity { private ListView mListView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mListView = (ListView) findViewById(R.id.list_view); // Now you can do whatever you want } }
Puedes hacerlo de la siguiente manera:
//your adapter for listview mAdapter = new ToDoListAdapter(getApplicationContext()); // Put divider between ToDoItems and FooterView getListView().setFooterDividersEnabled(true); // TODO - Inflate footerView for footer_view.xml file LayoutInflater layoutInflater = getLayoutInflater(); //text view or whatever you have for your footer TextView footerView = null; footerView=(TextView)layoutInflater.inflate(R.layout.footer_view,null); // TODO - Add footerView to ListView getListView().addFooterView(footerView); getListView().setAdapter(mAdapter);
Esto es dentro de su método onCreate (). Funcionó para mí. Dar comentarios si encuentra algún error aquí