make a listview fill the entire screen

0

I am developing an app where in one of the activities I have a listview. It is a dynamic listview that is completed with an own arrayadapter, so its extension is unknown. I would like it when it exceeds the size of the screen it reaches down and with scroll down.

To get this, I have to give a fixed size to the list, specifically 471, so that it occupies a large part of the screen and can go up and down. If I give it the match_parent property, it stays in a single row, and only one element remains up, I can scroll but all the elements are left there, up and small.

Is there a way to set the list for all the screens and that it is complete on the screen?

I leave the layout:

<?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"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.oftecnica2.agendajose.MainActivity"
    android:orientation="vertical"
    android:gravity="center"
    >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/scrollView"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true">


        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ListView
                android:layout_width="match_parent"
                android:id="@+id/lista"
                android:divider="@drawable/separador"
                android:layout_height="475dp" />
        </LinearLayout>
    </ScrollView>

</LinearLayout>

Here is the own layout that I use to fill the listview

<?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"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/shape">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:layout_width="53dp"
                android:layout_height="75dp"
                android:id="@+id/imageView"
                android:src="@drawable/iconoreunion" />

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:weightSum="1"
                    android:paddingBottom="5dp">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Nº"
                        android:id="@+id/textView"
                        android:paddingRight="10dp"
                        android:textColor="#000000" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:id="@+id/txtnumero"
                        android:paddingRight="30dp"
                        android:textColor="#000000" />

                </LinearLayout>

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:weightSum="1"
                    android:paddingBottom="5dp">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/Act1Fecha"
                        android:id="@+id/textView3"
                        android:paddingRight="10dp"
                        android:textColor="#000000" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:id="@+id/txtfecha"
                        android:paddingRight="10dp"
                        android:layout_weight="0.25"
                        android:textColor="#000000" />
                </LinearLayout>

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/Act1Nombre"
                        android:id="@+id/textView5"
                        android:paddingRight="10dp"
                        android:textColor="#000000" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:id="@+id/txtnombre"
                        android:paddingRight="30dp"
                        android:textColor="#000000" />

                </LinearLayout>
            </LinearLayout>
        </LinearLayout>



    </LinearLayout>

</LinearLayout>
    
asked by Sergio Cv 20.10.2016 в 11:46
source

4 answers

2

The first thing is that having a listview within a scrollview is a very bad idea, if you need to have a listview with superior or inferior views you must add the views above or below with the addHeaderView() and% methods addFooterView() .

What is surely happening to you is that the scrollView is taking the size of the listview so that the scrollview has the size of the whole screen add it:

android:fillViewport="true"

Greetings

    
answered by 20.10.2016 / 13:26
source
1

You can do this ..

<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

So you do not get complicated ... in this simple way you would have your screen just to show the ListView, well if the request asks for it.

    
answered by 20.10.2016 в 16:34
1

You tried to remove the Action Bar

<style name="NoActionBar" parent="@android:style/Theme.Holo.Light">
    <item name="android:windowActionBar">false</item>
    <item name="android:windowNoTitle">true</item>
</style> 
    
answered by 20.10.2016 в 21:15
0

First in your main container LinearLayout , You have defined:

  android:layout_width="match_parent"
  android:layout_height="match_parent"

Which is correct, but you have defined a padding which will generate space:

android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"

Eliminate padding.

Another important point is that you do not need a Scrollview to contain the ListView since it has its own Scroll, it eliminates the ScrollView and its LinearLayout .

This is an example:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

         <ListView
              android:id="@+id/list"
              android:layout_height="wrap_content"
              android:layout_width="match_parent">
         </ListView>

</LinearLayout>
    
answered by 20.10.2016 в 13:18