Search code examples
androidxmlandroid-scrollview

Android Scroll View space in the bottom


I want a help for design a screen.. I want to make a details screen, with a picture and a text (scrollabe).. But when i test, the text doesnt fill all the space...Its puts a empty space at the bottom of the text... How can i fill all the layout with the text?

<?xml version="1.0" encoding="utf-8"?>
<android.widget.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.rs.app.paginas.antena_detalhe">

    <LinearLayout
        android:layout_width="368dp"
        android:layout_height="495dp"
        android:orientation="vertical"
        android:weightSum="1"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="8dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_weight="0.05"
            android:gravity="center_vertical|center_horizontal"
            android:orientation="horizontal"
            tools:layout_editor_absoluteX="8dp"
            tools:layout_editor_absoluteY="0dp">

            <ImageView
                android:id="@+id/imgAntena"
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:layout_marginTop="10dp"
                android:layout_weight="1"
                app:srcCompat="@mipmap/baloon" />

        </LinearLayout>

        <TextView
            android:id="@+id/txtTitulo"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_marginBottom="10dp"
            android:layout_marginTop="10dp"
            android:gravity="center"
            android:text="Nome" />

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:adjustViewBounds="true"
            android:fillViewport="true"
            >

            <TextView
                android:id="@+id/txtDetalhes"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingLeft="5dp"
                android:paddingRight="5dp"
                android:scrollbars="vertical" />
        </ScrollView>

    </LinearLayout>

</android.widget.RelativeLayout>

and the screen:

enter image description here


Solution

  • You need to change to "match_parent" in your first LinearLayout´s height and widht parameters to fill all the screen, cause the parent in this case is your phone' screen, but if you define values in dp as shown in your code (495dp) then it´ll fill just that dimensions, and the screen dimensions change with every phone and his own screen size, that´s why it works in some little screen devices, and with bigger screens probably wont do it, the best solution to make it work with every screen size is changing your code like this:

    <?xml version="1.0" encoding="utf-8"?>
    <android.widget.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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.rs.app.paginas.antena_detalhe">
    
        <LinearLayout
            android:layout_width="match_parent"           
            android:layout_height="match_parent"          
            android:orientation="vertical"
            android:weightSum="1"
            tools:layout_editor_absoluteX="8dp"
            tools:layout_editor_absoluteY="8dp">
    
        ...
    

    Hope it helps,