Search code examples
androidheightspacefill

Android Studio - Fill remaining blank space (with height?)


I have this: Application

I want to grab the lighter blue text (code) and make it so it automatically fills the blank space if there is any, like so: example (it can be blank text).

Text code to be resized (second TextView unless you can resize the layout):

    <!-- Info -->
    <LinearLayout
        android:id="@+id/personalAppLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="@color/backgroundColor">

        <TextView
            android:id="@+id/descriptionTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/homepage_title"
            android:textAlignment="center"
            android:textStyle="bold"
            android:layout_marginTop="@dimen/activity_vertical_margin"/>

        <TextView
            android:id="@+id/description"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/homepage_description"
            android:textAlignment="center"
            android:layout_marginStart="@dimen/activity_horizontal_margin"
            android:layout_marginEnd="@dimen/activity_horizontal_margin"
            android:layout_marginTop="@dimen/activity_vertical_margin"
            android:layout_marginBottom="@dimen/activity_vertical_margin"/>

    </LinearLayout>

    <!-- Greyish Line -->
    <View
        android:layout_width="match_parent"
        android:layout_height="0.1dp"
        android:background="@color/backgroundColorDark" />

This is the code for the images: Images

    <!-- Info -->
    <LinearLayout
        android:id="@+id/personalAppLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="@color/backgroundColor">

        <TextView
            android:id="@+id/descriptionTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/homepage_title"
            android:textAlignment="center"
            android:textStyle="bold"
            android:layout_marginTop="@dimen/activity_vertical_margin"/>

        <TextView
            android:id="@+id/description"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/homepage_description"
            android:textAlignment="center"
            android:layout_marginStart="@dimen/activity_horizontal_margin"
            android:layout_marginEnd="@dimen/activity_horizontal_margin"
            android:layout_marginTop="@dimen/activity_vertical_margin"
            android:layout_marginBottom="@dimen/activity_vertical_margin"/>

    </LinearLayout>

Bottom navigation code: Bottom Navigation

    <!-- Bottom Navigation -->
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <android.support.design.widget.BottomNavigationView
            android:id="@+id/navigation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginEnd="0dp"
            android:layout_marginStart="0dp"
            android:background="?android:attr/windowBackground"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:menu="@menu/navigation"
            android:layout_alignParentBottom="true"/>

    </RelativeLayout>

Everything is inside a LinearLayout with vertical orientation, there are more layouts before these but I believe these are the ones that matter.

Is it possible to automatically fill the blank space on a cellphone without specifying a number of dp's?

Code as a whole (I intend to auto size the first LinearLayout until all remaining blank space is filled, without overlaping any of the other layouts)

EDIT: This is now changed to the complete working code, thanks to Rockney

<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">


<!-- Info -->
<LinearLayout
    android:id="@+id/personalAppLayout"
    android:layout_width="match_parent"
    <!-- Previously android:layout_height="wrap_content" and without a weight -->
    android:layout_height="0dp"
    android:weight="1"
    android:orientation="vertical"
    android:background="@color/backgroundColor">

    <TextView
        android:id="@+id/descriptionTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/homepage_title"
        android:textAlignment="center"
        android:textStyle="bold"
        android:layout_marginTop="@dimen/activity_vertical_margin"/>

    <TextView
        android:id="@+id/description"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/homepage_description"
        android:textAlignment="center"
        android:layout_marginStart="@dimen/activity_horizontal_margin"
        android:layout_marginEnd="@dimen/activity_horizontal_margin"
        android:layout_marginTop="@dimen/activity_vertical_margin"
        android:layout_marginBottom="@dimen/activity_vertical_margin"/>

</LinearLayout>

<!-- Greyish Line -->
<View
    android:layout_width="match_parent"
    android:layout_height="0.1dp"
    android:background="@color/backgroundColorDark" />

<!-- Social Media -->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="70dp"
    android:orientation="horizontal"
    android:background="@color/backgroundColor"
    android:gravity="center" >

    <ImageView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_margin="@dimen/activity_horizontal_margin"
        android:background="@drawable/linkedin_logo" />

    <ImageView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_margin="@dimen/activity_horizontal_margin"
        android:background="@drawable/facebook_logo" />

    <ImageView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_margin="@dimen/activity_horizontal_margin"
        android:background="@drawable/twitter_logo" />

</LinearLayout>

<!-- Greyish Line -->
<View
    android:layout_width="match_parent"
    android:layout_height="0.1dp"
    android:background="@color/backgroundColorDark" />

<!-- Bottom Navigation -->
<RelativeLayout
    android:layout_width="match_parent"
    <!-- Previously android:layout_height="match_parent" -->
    android:layout_height="60dp" >

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginEnd="0dp"
        android:layout_marginStart="0dp"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/navigation"
        android:layout_alignParentBottom="true"/>

</RelativeLayout>

</LinearLayout>

Solution

  • You can use layout-weight. It specifies how much of the extra space is located for the view. you can read more about in this stackoverflow post. You do need to change your layout to this.

    <LinearLayout
    android:id="@+id/personalAppLayout"
    android:layout_width="match_parent"
    android:layout_height="0dp”
    android:orientation="vertical"
    android:layout_weight=“1”
    android:background="@color/backgroundColor">
    
    <TextView
        android:id="@+id/descriptionTitle"
        android:layout_width="match_parent"
        android:layout_weight=“1”
        android:layout_height="0dp"
        android:text="@string/homepage_title"
        android:textAlignment="center"
        android:textStyle="bold"
        android:layout_marginTop="@dimen/activity_vertical_margin"/>
    
    <TextView
        android:id="@+id/description"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/homepage_description"
        android:textAlignment="center"
        android:layout_marginStart="@dimen/activity_horizontal_margin"
        android:layout_marginEnd="@dimen/activity_horizontal_margin"
        android:layout_marginTop="@dimen/activity_vertical_margin"
        android:layout_marginBottom="@dimen/activity_vertical_margin"/>
    
     </LinearLayout>