How to use Scrollview and Linearlayout with full screen height?

Asked

Viewed 1,178 times

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 the LinearLayout doesn’t take the whole screen and mine ListView only one item appears. I want it to appear according to the number of items.

2 answers

2


Thinking a little bit about your code, I realize that you don’t need to use a ListView within a ScrollView, that maybe, I say maybe it is not good practice. So that you do not see just one item as you are saying it is necessary to do this way 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>
  • I edited it so that Ad is aligned below.

  • Thank you now gave proper thank you

1

scrollView is only required if you have a component you want to see that is below the screen, in your case you don’t need scrollView pq the listview component itself already creates a scrolling list, after the main Relativelayout leaves only your Textview and your listview and makes a test, this last Relativelayout if there is nothing inside strip it tmb

  • I took as I said I edited my code on top. However my last Relativelayout and the application banner I can not take. I wanted to put it down when I got a big list of items the banner gets down from the screen.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.