【问题标题】:Remove white space from the bottom of screen Android从Android屏幕底部删除空白
【发布时间】:2017-10-07 06:18:54
【问题描述】:

如何删除屏幕底部的这个空白区域。我也试过android:adjustviewboundsandroid:scaletype。但仍然未能删除屏幕底部的空白。请帮我优化我的布局,以便我可以从底部删除那个丑陋的空白。

这是我的布局屏幕下面的屏幕截图。

这是我的布局的 XML 代码。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="wrap_content"
android:layout_width="match_parent"
tools:context="com.example.zohai.v360.Fragments.Home">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="190dp"
            android:layout_marginTop="-15dp">
            <ImageView
                android:id="@+id/intro"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:scaleType="fitXY"
                android:adjustViewBounds="true"
                android:background="@drawable/intro"/>
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="190dp"
            android:layout_marginTop="-15dp"
            >

            <ImageView
                android:id="@+id/photog"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/photographers"
                android:adjustViewBounds="true"
                android:scaleType="fitXY"
                />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="190dp"
            android:layout_marginTop="-14dp">
            <ImageView
                android:id="@+id/model"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/model_bg"
                android:adjustViewBounds="true"
                android:scaleType="fitXY"
                />

        </LinearLayout>

    </LinearLayout>

</ScrollView>

</RelativeLayout>

【问题讨论】:

  • 这是空白部分,因为在 3x190 之后仍有一些屏幕高度,您为什么使用负边距...?
  • 从你的问题我可以理解的是,你有这三张图片,你希望它占据你的整个屏幕,不留空白。这是你想要的吗?
  • 是的,这正是我想要的
  • 我使用负边距去除图像之间的空白
  • 只需使用工具栏中使用的背景图片即可。顺便说一句……你为什么要使用所有那些毫无意义的线性布局?!尽快将它们全部删除!嵌套布局不利于性能

标签: android android-layout scrollview


【解决方案1】:

在您提到的 xml 代码中

android:layout_height="190dp"

这通常对android:scaletype没有帮助

请您的约束布局带权重的线性布局将3个线性布局分配到屏幕高度。像这样,

 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_marginTop="-15dp">
 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_marginTop="-15dp">
 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_marginTop="-15dp">

然后使用android:scaletype 来适应LinearLayout

注意:不同的屏幕尺寸很重要,我认为在您的情况下屏幕高度很高,这会导致布局底部有空白区域。在小尺寸屏幕上可能不是这样。尝试以上操作将有助于所有屏幕尺寸

【讨论】:

    【解决方案2】:

    您的布局高度设置为wrap_content。空白在那里是因为您没有足够的内容大小来完全填满屏幕。如果将高度设置为match_parent,则可以通过在根视图上设置android:background 来消除空白。

    否则你必须在那里找到你想要的东西。更改图像的大小是个坏主意,因为它们看起来会被拉伸。

    而且由于 android 是一个大平台,您会看到在某些设备上不会出现空白,而在其他设备上会更大。不要将图像的大小设置为固定大小。

    【讨论】:

    • 我正在使用滚动视图,因此滚动视图内的布局无法设置为 android:height = "match_parent"
    • 我已将根布局(相对布局)高度设置为与父级匹配,但仍然存在空白
    • 错误。您可以将 ScrollView 和 RelativeLayout 的高度设置为match_parent。就是ScrollView里面的LinearLayout需要是wrap_content
    猜你喜欢
    • 1970-01-01
    • 2015-06-28
    • 2020-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-02
    相关资源
    最近更新 更多