2016-04-30 68 views
2

我正在使用RecyclerView來顯示項目列表,我想在列表下面顯示一個包含一些細節的框,但我不怎麼做,我嘗試了很多事情,但我不能顯示我想要的框。顯示下面的LinearLayout RecyclerView

我的想法是在下面的圖片中實現類似:

​​

下面是我的代碼:

<?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" 
    android:fitsSystemWindows="true" 
    tools:context="...MainActivity" 
    android:background="@color/backgroundColor"> 

    <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> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/user_subscriptions" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingTop="12dp" 
     android:paddingBottom="10dp" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 


    // HERE I'M TRYING TO ADD THE BOX. 


    <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" /> 

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

任何想法,我該怎麼辦呢?謝謝!

+0

使用TabLayout下來 – Andro

+0

@ANDRO ??我不想顯示任何標籤。 – gon250

+1

使用家長作爲相對佈局和佈局,你想添加將它設置爲父母的底部和我們的回收站上方的視圖 –

回答

7

試試這個,希望這會幫助你。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    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: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:layout_above="@+id/bottomBox" 
     android:fitsSystemWindows="true"> 

     <android.support.design.widget.AppBarLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

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

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

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/user_subscriptions" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:paddingBottom="10dp" 
      android:paddingTop="12dp" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/fab" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom|end" 
      android:layout_margin="15dp" 
      android:background="@color/colorPrimary" /> 


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

    <LinearLayout 
     android:id="@+id/bottomBox" 
     android:layout_width="match_parent" 
     android:layout_height="60dp" 
     android:layout_alignParentBottom="true" 
     android:background="@android:color/white" 
     android:orientation="vertical" /> 

</RelativeLayout> 
0

您的RecyclerView的高度爲match_parent。所以你不能在下面顯示任何東西,因爲它會佔用所有的屏幕高度。

0

你可以像下面這樣做

<?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" 
    android:fitsSystemWindows="true" 
    tools:context="...MainActivity" 
    android:background="@color/backgroundColor"> 

    <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> 

    // HERE I'M TRYING TO ADD THE BOX. 

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

     <View 
      android:id="@+id/box" 
      android:layout_width="match_parent" 
      android:layout_height="50dp" 
      android:layout_alignParentBottom="true" 
      /> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/user_subscriptions" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:paddingTop="12dp" 
      android:paddingBottom="10dp" 
      android:layout_above="@id/box" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

    </RelativeLayout> 


    <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" /> 

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

使用應用:layout_behavior =「@字符串/ appbar_scrolling_view_behavior這樣的: -

<?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" 
    android:fitsSystemWindows="true" 
    tools:context="...MainActivity" 
    android:background="@color/backgroundColor"> 

    <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> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/user_subscriptions" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingTop="12dp" 
     android:paddingBottom="10dp" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 


    <LinearLayout 
    android:id="@+id/bottomBox" 
    android:layout_width="match_parent" 
    android:layout_height="60dp" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior 
    android:background="@android:color/white" 
    android:orientation="vertical" /> 


    <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" /> 

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

我嘗試過如何在一個視圖低於recyclerview迫使mych我意識到它的一個簡單任務。

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_height="wrap_content" 
android:fillViewport="true"> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
     <LinearLayout 
      android:id="@+id/line1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:layout_gravity="center" 
      android:padding="16dp"> 

      <Button 
       android:layout_below="@+id/recycler_view" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Create Group" 
       android:layout_gravity="center" 
       style="@style/Button.Primary"/> 
      <ImageView 
       android:id="@+id/image_view_group_image" 
       android:layout_width="120dp" 
       android:layout_height="120dp" 
       android:layout_margin="16dp" 
       android:layout_gravity="center" 
       android:scaleType="centerInside" 
       android:background="@color/colorPrimary" 
       android:src="@drawable/ic_edit_white_24dp"/> 
      <TextView 
       android:layout_below="@+id/image_view_group_image" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="16dp" 
       android:layout_gravity="center" 
       android:text="Please add an icon for your group"/> 
      <android.support.design.widget.TextInputLayout 
       android:id="@+id/text_input_layout1" 
       android:layout_below="@+id/image_view_group_image" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="8dp" 
       android:hint="Type your group subject here"> 
       <android.support.design.widget.TextInputEditText 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" /> 
      </android.support.design.widget.TextInputLayout> 

      <android.support.design.widget.TextInputLayout 
       android:id="@+id/text_input_layout" 
       android:layout_below="@+id/text_input_layout1" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="8dp" 
       android:hint="Add Members"> 
       <android.support.design.widget.TextInputEditText 
        android:id="@+id/text_input_layout_add_members" 
        android:layout_width="match_parent" 
        android:drawableRight="@drawable/ic_search_grey_600_24dp" 
        android:drawableEnd="@drawable/ic_search_grey_600_24dp" 
        android:layout_height="wrap_content" /> 
      </android.support.design.widget.TextInputLayout> 
     </LinearLayout> 
    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recycler_view" 
     android:layout_below="@+id/line1" 
     android:layout_marginTop="16dp" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 
</RelativeLayout>