android视图之间的额外空格

时间:2017-02-17 12:49:51

标签: android layout view android-recyclerview

在以下布局中,在AppBarLayout之后和RecyclerView之前,有一些额外的空白即将到来,我无法弄清楚它是如何发生的。

我检查了保证金,所有,似乎没事。

同样由于同样的原因,我相信RecyclerView的最后一个元素被裁剪出布局视图。

任何帮助表示感谢。

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/transMain"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/app_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            android:theme="@style/AppTheme.AppBarOverlay">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/toolbar_layout"
                android:layout_width="match_parent"
                android:layout_height="80dp"
                android:fitsSystemWindows="true"
                android:paddingLeft="12dp"
                app:contentScrim="?android:attr/colorPrimary"
                app:layout_scrollFlags="exitUntilCollapsed">

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbarAct"
                    android:layout_width="match_parent"

                    android:layout_height="wrap_content"
                    android:background="@color/colorPrimary"
                    app:layout_scrollFlags="scroll">

                    <RelativeLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content">

                        <!--button was here-->

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

                            <RelativeLayout
                                android:id="@+id/monthSelLay"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content">

                                <TextView
                                    android:id="@+id/monthButton"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_marginTop="8dp"
                                    android:textColor="#000"
                                    android:textSize="14sp" />

                                <ImageView
                                    android:layout_width="22dp"
                                    android:layout_height="22dp"
                                    android:layout_marginTop="12dp"
                                    android:layout_toRightOf="@id/monthButton"
                                    android:src="@drawable/ic_keyboard_arrow_down_black_24dp" />
                            </RelativeLayout>

                            <RelativeLayout
                                android:id="@+id/syncLay"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content">

                                <TextView
                                    android:id="@+id/syncButton"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_marginLeft="50dp"
                                    android:layout_marginTop="8dp"
                                    android:text="SyncUp"
                                    android:textAlignment="center"
                                    android:textColor="#000" />

                                <ImageView
                                    android:layout_width="22dp"
                                    android:layout_height="22dp"
                                    android:layout_marginTop="5dp"
                                    android:layout_toRightOf="@+id/syncButton"
                                    android:src="@drawable/ic_cached_black_48dp" />
                            </RelativeLayout>

                        </LinearLayout>
                        <!--switch was here-->

                    </RelativeLayout>
                </android.support.v7.widget.Toolbar>
            </android.support.design.widget.CollapsingToolbarLayout>


            <android.support.v7.widget.SearchView
                android:id="@+id/searchTrans"
                android:layout_width="350dp"
                android:layout_height="40dp"
                android:layout_below="@+id/toolbar"
                android:layout_gravity="center_horizontal"

                android:layout_marginBottom="10dp"
                android:layout_marginTop="10dp"
                android:background="#fff"
                android:hint="Start typing an Amount/Description"
                android:textColor="#000"
                android:textColorHint="#ccc"
                app:tabMode="scrollable" />

            <!--need to change the background as an object oval prbbly-->
        </android.support.design.widget.AppBarLayout>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/trans"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center_horizontal"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

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


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

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@drawable/ic_add_black_24dp"
        app:backgroundTint="@color/colorAccent"
        app:elevation="6dp"
        app:pressedTranslationZ="12dp" />

</FrameLayout>

在第一张图片中,我略微向上滚动以显示空白。

enter image description here

裁剪后的最后一个元素RecyclerViewenter image description here

2 个答案:

答案 0 :(得分:1)

从RecyclerView

中删除此行
android:layout_gravity="center_horizontal"

答案 1 :(得分:0)

删除此行:

android:layout_gravity="center_horizontal"

使协调员身高达到wrap_content

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
                                                         xmlns:app="http://schemas.android.com/apk/res-auto"
                                                         android:id="@+id/transMain"
                                                         android:layout_width="match_parent"
                                                         android:layout_height="wrap_content"
                                                         android:fitsSystemWindows="true">