0

How do I remove this unnecessary white space (refer screenshot) between the navigation bar and layout? In the android studio, there is no white space shown but when running the app this unwanted white space added automatically. I tested this on two real android devices and emulator and the results were the same.

real time image

layout XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="false"
android:focusableInTouchMode="false"
android:orientation="vertical"
android:visibility="visible"
android:weightSum="1"
tools:context="com.test.test.MainActivity">

<ImageView
    android:id="@+id/imageView"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.9"
    android:adjustViewBounds="true"
    android:scaleType="fitCenter"
    android:visibility="visible" />

<HorizontalScrollView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.1"
    android:background="@color/blueui"
    android:fillViewport="true">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <Button
            android:id="@+id/btn1"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/button_background"
            android:clickable="true"
            android:focusable="true"
            android:text="@string/btn1"
            android:textAllCaps="false"
            android:textColor="@android:color/white"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btn2"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/button_background"
            android:clickable="true"
            android:focusable="true"
            android:text="@string/btn2"
            android:textAllCaps="false"
            android:textColor="@android:color/white"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btn3"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/button_background"
            android:clickable="true"
            android:focusable="true"
            android:text="@string/btn3"
            android:textAllCaps="false"
            android:textColor="@android:color/white"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btn4"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/button_background"
            android:clickable="true"
            android:focusable="true"
            android:text="@string/btn4"
            android:textAllCaps="false"
            android:textColor="@android:color/white"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btn5"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/button_background"
            android:clickable="true"
            android:focusable="true"
            android:text="@string/btn5"
            android:textAllCaps="false"
            android:textColor="@android:color/white"
            android:textSize="12sp" />

        <Button
            android:id="@+id/btn6"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/button_background"
            android:clickable="true"
            android:focusable="true"
            android:text="@string/btn6"
            android:textAllCaps="false"
            android:textColor="@android:color/white"
            android:textSize="12sp" />
    </LinearLayout>
</HorizontalScrollView>
</LinearLayout>

app theme

<resources>

<style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>

</style>
</resources>
d91
  • 83
  • 1
  • 8

1 Answers1

0

That is due to the HorizontalScrollView scrollbar location, if you would like to use the same code but have the white area go away you may change the layout_weight to 0.11 and it might resolve your issue but might ruin the display of the button image.

<HorizontalScrollView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.11"
    android:background="@color/blueui"
    android:fillViewport="true">
.....
</HorizontalScrollView>
  • hi thank you for this. yes but i tried similar by adding android:layout_marginBottom="-1dp" to root linearayout but in android studio the layout goes on top of nav bar and that will lead to future problems i guess.(not sure how this will go with every screen sizes available). Logically weights must be equal to 1 isn't it? :) – d91 Nov 11 '20 at 17:35
  • Some say having a negative margin is a viable solution while others say it is not. You may check this post for different views: https://stackoverflow.com/q/10673503/2335336 . As long as your View does not have a 'clickable' button/object within the negative values I assume it should not be an issue. – Mazin Al-Bahrani Nov 11 '20 at 18:44