2017-09-04 74 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

相關問題