Android片段底部奇怪的空白区域?

时间:2016-04-21 05:42:32

标签: android xml android-fragments layout fragment

我遇到了一个奇怪的问题:片段底部有一个空白区域,我无法摆脱它。值得一提的是,如果我点击任何按钮,这个空间就会消失。

任何帮助表示赞赏!请在下面找到截图和布局代码。

Screenshot

DetailActivity布局:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/detail_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.ogasimli.manat.activity.DetailActivity"
tools:ignore="MergeRootFrame" />

DetailFragment布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.ogasimli.manat.fragment.DetailActivityFragment"
android:background="@color/colorAccent">

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/detail_result_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:visibility="gone"
    tools:visibility="visible">

    <android.support.design.widget.AppBarLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        app:elevation="0dp"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar_detail"
            android:layout_width="match_parent"
            android:layout_height="?actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.AppBarOverlay"/>

    </android.support.design.widget.AppBarLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_marginTop="?actionBarSize"
        android:weightSum="7">

        <include layout="@layout/detail_chart_grid"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="4.5"/>

        <include layout="@layout/detail_extras_grid"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="2.5"/>

    </LinearLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_share_details"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="24dp"
        android:elevation="8dp"
        android:src="@drawable/ic_share"
        app:layout_anchor="@id/cardview_details"
        app:layout_anchorGravity="top|right|end"
        app:rippleColor="@color/colorPrimary"
        tools:targetApi="lollipop"/>

</android.support.design.widget.CoordinatorLayout>

<LinearLayout
    android:id="@+id/detail_error_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_centerInParent="true"
    android:orientation="vertical"
    android:visibility="gone">

    <include
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        layout="@layout/error_view"
        android:layout_gravity="center"/>

</LinearLayout>

详细图表网格布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"  xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:background="@color/colorPrimary">

<com.github.mikephil.charting.charts.LineChart
    android:id="@+id/linechart"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_margin="10dp"
    android:layout_weight="3"/>

<include layout="@layout/detail_button_grid"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_gravity="center"
    android:layout_marginBottom="26dp"
    android:layout_marginEnd="16dp"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    android:layout_marginStart="16dp"
    android:layout_marginTop="16dp"
    android:layout_weight="1"/>

</LinearLayout>

详细信息附加网格布局:

<?xml version="1.0" encoding="utf-8"?>
<!-- Detail Layout for Grid -->
<android.support.v7.widget.CardView
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/cardview_details"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_gravity="center"
app:contentPaddingLeft="16dp"
app:contentPaddingRight="22dp"
app:cardCornerRadius="16dp"
app:cardBackgroundColor="?colorAccent"
app:cardElevation="0dp">

<android.support.v7.widget.GridLayout
    android:id="@+id/detail_additional_pane"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="2"
    app:columnCount="2">

    <TextView
        android:id="@+id/detail_statistic_label_text_view"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:textAllCaps="true"
        android:fontFamily="sans-serif-medium"
        android:textColor="?colorPrimary"
        android:text="@string/detail_statistics_label"
        android:minHeight="48dp"
        android:textSize="18sp"
        app:layout_columnWeight="1"
        app:layout_gravity="fill"
        app:layout_rowWeight="1"
        app:layout_columnSpan="2"/>

    <TextView
        android:layout_height="wrap_content"
        android:text="Current rate"
        android:gravity="center_vertical"
        android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
        android:paddingBottom="5dp"
        app:layout_columnWeight="1"
        app:layout_gravity="fill"
        app:layout_rowWeight="1"/>

    <TextView
        android:id="@+id/detail_current_rate_textview"
        android:gravity="center_vertical"
        android:fontFamily="sans-serif-light"
        android:textColor="@color/colorTextPrimary"
        android:textSize="18dp"
        android:paddingBottom="5dp"
        app:layout_gravity="right"
        tools:text="1.5571"/>

    <TextView
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:text="Average rate"
        android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
        android:paddingBottom="5dp"
        app:layout_columnWeight="1"
        app:layout_gravity="fill"
        app:layout_rowWeight="1"/>

    <TextView
        android:id="@+id/detail_average_rate_textview"
        android:gravity="center_vertical"
        android:fontFamily="sans-serif-light"
        android:textColor="@color/colorTextPrimary"
        android:textSize="18dp"
        android:paddingBottom="5dp"
        app:layout_gravity="right"
        tools:text="1.567"/>

    <TextView
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:text="Maximum rate"
        android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
        android:paddingBottom="5dp"
        app:layout_columnWeight="1"
        app:layout_gravity="fill"
        app:layout_rowWeight="1"/>


    <TextView
        android:id="@+id/detail_max_rate_textview"
        android:gravity="center_vertical"
        android:fontFamily="sans-serif-light"
        android:textColor="@color/colorTextPrimary"
        android:textSize="18dp"
        android:paddingBottom="5dp"
        app:layout_gravity="right"
        tools:text="1.602"/>

    <TextView
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:text="Minimum rate"
        android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
        android:paddingBottom="5dp"
        app:layout_columnWeight="1"
        app:layout_gravity="fill"
        app:layout_rowWeight="1"/>


    <TextView
        android:id="@+id/detail_min_rate_textview"
        android:gravity="center_vertical"
        android:fontFamily="sans-serif-light"
        android:textColor="@color/colorTextPrimary"
        android:textSize="18dp"
        android:paddingBottom="5dp"
        app:layout_gravity="right"
        tools:text="1.5571"/>

</android.support.v7.widget.GridLayout>

</android.support.v7.widget.CardView>

3 个答案:

答案 0 :(得分:4)

调试奇怪空格和边距的最佳方法是使用XML快照。

Android studio中,点击&#34; Android device monitor&#34;按钮(绿色机器人图标) 在设备监视器中,确保在左窗格中选择了您的设备,然后单击&#34; Dump view hierarchy&#34;按钮(3个电话图标)。 然后,您应该看到可见屏幕的屏幕截图,其中xml在右侧创建了它。 您可以将鼠标悬停在底部间距上,以查看xml中的来源。

答案 1 :(得分:2)

<强>解决

正如所建议的@marmor所使用的Android设备监视器,并显示该片段的根目录存在问题。因此,我决定遵循@DanielNugent的建议并制作片段的CoordinatorLayout根布局,之后奇数空格消失。

答案 2 :(得分:0)

在我的情况下,问题不仅出现在CoordinatorLayoutActivity的{​​{1}}中(正如Orkhan Gasimli建议的那样,我在Fragment中变成了ConstraintLayout)。

FragmentAndroid How to adjust layout in Full Screen Mode when softkeyboard is visible)在全屏模式下调整布局时出现问题。首先是全屏显示,然后更改为通常的样式,并出现空白(SoftInputAssist比片段容器有更多的空间)。在这种情况下,请移除id/content并查看https://stackoverflow.com/a/52850584/2914140