繁体   English   中英

删除导航栏上方不必要的空白

[英]Remove unnecessary white space above navigation bar

如何删除导航栏和布局之间不必要的空白区域(请参阅屏幕截图)? 在 android 工作室中,没有显示空白,但在运行应用程序时会自动添加这个不需要的空白。 我在两个真实的 android 设备和模拟器上测试了这个,结果是一样的。

实时图像

布局 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>

应用主题

<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>

这是由于 Horizo HorizontalScrollView滚动条的位置,如果您想使用相同的代码但没有白色区域 go,您可以将layout_weight更改为 0.11,这可能会解决您的问题,但可能会破坏按钮图像的显示。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM