2017-09-04 75 views
-4

我想要使Android应用程序和应用程序包含RecyclerViewMainActivityRecyclerView不采取全屏幕,有顶部的空间和底部android-为什么在顶部和底部的空间RecyclerView

activity_main.xml文件:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.multiplies.multiring.MainActivity"> 

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

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

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

    <include 
     layout="@layout/recyclerview_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/include" /> 

    <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" 
     app:fabSize="normal" 
     app:srcCompat="@drawable/plus" /> 

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

recyclerview_layout.xml文件:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="com.multiplies.multiring.MainActivity" 
    tools:showIn="@layout/activity_main"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recyclerview" 
     android:layout_width="368dp" 
     android:layout_height="495dp" 
     android:layout_marginBottom="8dp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" /> 

</android.support.constraint.ConstraintLayout> 
+0

边距和补加的空间。而且,嵌套布局会导致糟糕的性能。此外......如果您选择使用ContraintLayout,那么为什么您会在其中放置一个RelativeLayout? –

回答

0

对于戈巴托你有一个“保证金底”,所以这是正常的。 而我没有看到Top的限制。

+0

我做了你说的,它的底部工作良好,但它看起来工具栏是在recyclerview前,所以我不能看到冷杉项目我如何修复它 –

0

在你的回收站视图中删除

android:layout_marginBottom="8dp" 

并设置

android:layout_height="match_parent" 
+0

我做了你说的,它的工作良好底部,但它看起来,工具栏是在recyclerview前,所以我看不到冷杉项目我如何修复它 –

+0

CoordinatorLayout是伴随着定义它的孩子在Java中的行为。如果你没有这样做,你应该用其他布局替换它,如果你这样做,那么你应该使用'CoordinatorLayout.Behavior'来使你的工具栏可见。 – Gotiasits

相关问题