2016-01-24 73 views
2

我試圖讓快餐欄下面的3個選項卡。我已經誇大了一個片段,並在那裏實施了協調員佈局。我無法在tab下面顯示快餐欄。並且getView ()在浮動按鈕上方的底部顯示快餐欄,並且此代碼How to show Snackbar at top of the screen在頂部顯示快餐欄,這是我不想要的。如何使小吃店顯示在片段下的標籤?小吃店沒有出現在viewpager中的片段佈局/ recyclerview內

代碼:

Snackbar snackbar = Snackbar 
         .make(coordinatorLayout_snackbar, 「Snackbar」, Snackbar.LENGTH_INDEFINITE) 
         .setAction(「click」, new View.OnClickListener() { 
          @Override 
          public void onClick(View view) { 
           Log.e(TAG, "button clicked"); 
          } 
         }); 

       snackbar.show(); 

XML:

<?xml version="1.0" encoding="utf-8"?> 


<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:fab="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/frame_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.design.widget.CoordinatorLayout 
     android:id="@+id/coordinatorLayout_snackbar」 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_alignParentTop="true"> 
</android.support.design.widget.CoordinatorLayout> 


    <android.support.v4.widget.SwipeRefreshLayout 
     android:id="@+id/swipe_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 


     <android.support.v7.widget.RecyclerView 
      android:id="@+id/recyclerview" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:scrollbars="vertical" /> 
    </android.support.v4.widget.SwipeRefreshLayout> 

</FrameLayout> 

回答

3

你需要用你的SwipeRefreshLayout的CoordinatorLayout裏面,像這樣:

<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:fab="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/coordinatorLayout_snackbar」 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.v4.widget.SwipeRefreshLayout 
     android:id="@+id/swipe_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/recyclerview" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:scrollbars="vertical" /> 
    </android.support.v4.widget.SwipeRefreshLayout> 

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

在當前的佈局,SwipeRefreshLayout是繪製在高度爲0的CoordinatorLayout上,因爲它沒有孩子和身高設置爲wrap_content。

+0

我怎麼能把它放在最上面,它現在甚至不會顯示,直到我向下滾動。它是隱藏的。 – jason

+1

您必須將CoordinatorLayout放入活動佈局中,以便整個片段包含在CoordinatorLayout中。 – patloew

+0

CAn您請通過代碼解釋?我試過了,它仍然顯示在佈局下方。 – jason