mark
mark

Reputation: 105

White space at the top of the screen in android app, but I don't know why (Android)

I am currently making a very simple app. However, there is this massive white space at the top of the screen and I don't know what is causing it or how I could remove it. All I have in my XML are a few textviews and a radiogroup, so I'm not sure what is causing the black space. enter image description here

Here is my XML code:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".ui.home.HomeFragment"
    android:layout_margin="20sp">

    <TextView
        android:id="@+id/text_home"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:textAlignment="center"
        android:textSize="30sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:text="Find fragment"

        android:textStyle="bold"
        android:textColor="@color/design_default_color_primary_dark"/>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="50sp"
        android:text="Select the desired type of tea"
        android:textSize="20sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.155" />

    <RadioGroup
        android:id="@+id/radioGroup"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@+id/textView2">

        <RadioButton
            android:id="@+id/greentea"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Green Tea" />

        <RadioButton
            android:id="@+id/blacktea"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Black Tea" />

        <RadioButton
            android:id="@+id/herbaltea"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Herbal Tea" />

        <RadioButton
            android:id="@+id/alltea"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="All" />

    </RadioGroup>

    <com.google.android.material.button.MaterialButton
        android:layout_width="170sp"
        android:layout_height="60sp"
        android:layout_marginTop="20sp"
        android:text="Go to results"
        android:textSize="15sp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/radioGroup" />



</androidx.constraintlayout.widget.ConstraintLayout>

Any help would be greatly appreciated!

Upvotes: 0

Views: 224

Answers (1)

livenlearnaday
livenlearnaday

Reputation: 161

It's the layout_margin that is pushing down the margin at the top. When you use layout_margin, it applies to all direction.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".ui.home.HomeFragment"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:layout_marginBottom="20dp">

    <TextView
        android:id="@+id/text_home"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:textAlignment="center"
        android:textSize="30sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:text="Find fragment"

        android:textStyle="bold"
        android:textColor="@color/design_default_color_primary_dark"/>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="50sp"
        android:text="Select the desired type of tea"
        android:textSize="20sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.155" />

    <RadioGroup
        android:id="@+id/radioGroup"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@+id/textView2">

        <RadioButton
            android:id="@+id/greentea"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Green Tea" />

        <RadioButton
            android:id="@+id/blacktea"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Black Tea" />

        <RadioButton
            android:id="@+id/herbaltea"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Herbal Tea" />

        <RadioButton
            android:id="@+id/alltea"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="All" />

    </RadioGroup>

    <com.google.android.material.button.MaterialButton
        android:layout_width="170sp"
        android:layout_height="60sp"
        android:layout_marginTop="20sp"
        android:text="Go to results"
        android:textSize="15sp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/radioGroup" />



</androidx.constraintlayout.widget.ConstraintLayout>

Upvotes: 1

Related Questions