How to use ScrollView and LinearLayout with full screen height?

0

I have my code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="@+id/content_reserva"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="fabiohcnobre.jhotelcolonialdosnobres.ReservaActivity"
    tools:showIn="@layout/app_bar_reserva">


   <RelativeLayout
        android:id="@+id/adViewContainer"
        android:layout_width="match_parent"
        android:layout_height="50dp" />
    <TextView
        android:text="@string/subtitle_reserva"
        android:layout_width="match_parent"
        android:id="@+id/TextView1"
        android:layout_height="50dp" />

    <ListView
        android:id="@+id/lv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/cardview_dark_background"/>


</RelativeLayout>

But LinearLayout does not take the whole screen and my ListView only one item appears. I want it to appear according to the number of items.

    
asked by anonymous 15.10.2016 / 02:27

2 answers

2

Thinking a bit about your code, I realize that you do not need to use ListView within ScrollView , which maybe, I say, might not be good practice. In order for you not to see just one item as you are saying it is necessary to do this below:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/content_reserva"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <TextView
        android:text="TESTE"
        android:layout_width="match_parent"
        android:id="@+id/TextView1"
        android:gravity="center"
        android:layout_height="wrap_content" />

    <ListView
        android:id="@+id/lv"
        android:layout_width="wrap_content"
        android:background="@color/cardview_dark_background"
        android:layout_height="match_parent"
        android:layout_below="@+id/TextView1"/>

    <RelativeLayout
        android:id="@+id/adViewContainer"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@android:color/darker_gray"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true">

        -> aqui vai ficar o ad <-

    </RelativeLayout>

</RelativeLayout>
    
15.10.2016 / 03:51
1

The scrollView is only necessary if you have a component that you want to see that is below the screen, in your case you do not need scrollView because the listView component already creates a scrolling list, after the main RelativeLayout leaves only its Textview and your listView and does a test, that last RelativeLayout if it has nothing in it strip it tmb

    
15.10.2016 / 03:34