Scrollview with Relativelayout

Asked

Viewed 452 times

0

How do I make for the RelativeLayout occupy the entire height of the screen inside the ScrollView? (tried wrap_contet but as I have advertised Admob she gives error with the button)

Code:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:paddingBottom="0dp"
    android:paddingLeft="0dp"
    android:paddingRight="0dp"
    android:paddingTop="0dp"
    tools:context="alcoolougasolina.aplicativo.MainActivity"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true">


    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="400dp">


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="Descubra qual combustivel é mais vantajoso abastecer."
                android:id="@+id/textView3"
                android:layout_alignParentTop="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_marginTop="20dp"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="16dp" />


            <com.google.android.gms.ads.AdView
                android:id="@+id/adView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                ads:adSize="BANNER"
                ads:adUnitId="ca-app-pub-7380991228143623/3071936395"
                android:layout_alignParentTop="false"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true">
            </com.google.android.gms.ads.AdView>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="Preço Gasolina:"
                android:id="@+id/textView"
                android:layout_below="@+id/textView3"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="16dp"
                android:layout_marginTop="20dp" />

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="numberDecimal"
                android:ems="10"
                android:id="@+id/editText"
                android:layout_below="@+id/textView"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_marginTop="0dp"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="16dp"
                android:text="@string/edt1" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="Preço Álcool:"
                android:id="@+id/textView2"
                android:layout_below="@+id/editText"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_marginTop="25dp"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="16dp" />

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="numberDecimal"
                android:ems="10"
                android:id="@+id/editText2"
                android:layout_below="@+id/textView2"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="16dp"
                android:text="@string/edt2" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/bt1"
                android:id="@+id/Calcular"
                android:layout_below="@+id/editText2"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="30dp"
                android:onClick="calculo"
                android:layout_marginBottom="30dp" />


        </RelativeLayout>
    </LinearLayout>
</ScrollView>

Imagery:

inserir a descrição da imagem aqui

1 answer

1


You have to let your ScrollView take up all the space on the screen by changing its height to match_parent, then yes so all content that is inside

match_parent: View must occupy the same space as your Parent View (Father view). In any dimension(height and/or width)

fill_parent: Same match_parent function, but used in android 2.1, when the update was made to 2.3, was discontinued at use of match_parent.

wrap_content: View should only take up the space you need (height and/or width) to display your information in the layout.

Scrollview attributes would be like this, occupying all space both vertically and horizontally:

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

See the image below:

inserir a descrição da imagem aqui

Browser other questions tagged

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