2017-04-10 90 views
2

根據以下評論,我更改了我的layout。它正在工作,但是當我到達recyclerview中的項目底部並嘗試向上滾動時,它僅上升到recyclerview的開頭。我必須再次滾動才能到達header帶有CoordinatorLayout和AppBarLayout的Recyclerview

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

<android.support.design.widget.CoordinatorLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/white"> 

     <android.support.constraint.ConstraintLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      app:layout_scrollFlags="scroll"> 

      <de.hdodenhof.circleimageview.CircleImageView 
       android:id="@+id/iv_profile" 
       android:layout_width="70dp" 
       android:layout_height="70dp" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:layout_centerVertical="true" 
       android:layout_marginLeft="8dp" 
       android:layout_marginStart="8dp" 
       android:layout_marginTop="15dp" 
       android:gravity="center_vertical" 
       android:src="@drawable/ap_placeholder" 
       app:layout_constraintLeft_toLeftOf="parent" 
       app:layout_constraintTop_toTopOf="parent"/> 

      <TextView 
       android:id="@+id/tv_profile_name" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="8dp" 
       android:layout_marginStart="8dp" 
       android:layout_marginTop="25dp" 
       android:text="@string/profile_name" 
       app:layout_constraintLeft_toRightOf="@+id/iv_profile" 
       app:layout_constraintTop_toTopOf="parent"/> 

      <TextView 
       android:id="@+id/tv_username" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="8dp" 
       android:layout_marginStart="8dp" 
       android:layout_marginTop="8dp" 
       android:text="@string/username" 
       android:textStyle="bold" 
       app:layout_constraintLeft_toRightOf="@+id/iv_profile" 
       app:layout_constraintTop_toBottomOf="@+id/tv_profile_name"/> 

      <ImageView 
       android:id="@+id/iv_settings" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginEnd="16dp" 
       android:layout_marginRight="16dp" 
       android:layout_marginTop="33dp" 
       android:contentDescription="@string/settings_content_description" 
       app:layout_constraintRight_toRightOf="parent" 
       app:layout_constraintTop_toTopOf="parent" 
       app:srcCompat="@drawable/ap_settings"/> 

      <TextView 
       android:id="@+id/tv_profile_description" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_marginEnd="16dp" 
       android:layout_marginLeft="16dp" 
       android:layout_marginRight="16dp" 
       android:layout_marginStart="16dp" 
       android:layout_marginTop="8dp" 
       android:ellipsize="end" 
       android:maxLines="2" 
       android:text="@string/profile_description" 
       app:layout_constraintLeft_toLeftOf="parent" 
       app:layout_constraintRight_toRightOf="parent" 
       app:layout_constraintTop_toBottomOf="@+id/iv_profile"/> 

      <View 
       android:id="@+id/view" 
       android:layout_width="0dp" 
       android:layout_height="1dp" 
       android:layout_marginTop="20dp" 
       android:background="@color/light_grey" 
       app:layout_constraintLeft_toLeftOf="parent" 
       app:layout_constraintRight_toRightOf="parent" 
       app:layout_constraintTop_toBottomOf="@+id/tv_profile_description"/> 

      <com.roughike.bottombar.BottomBar 
       android:id="@+id/bottom_bar" 
       android:layout_width="0dp" 
       android:layout_height="60dp" 
       android:layout_marginTop="20dp" 
       android:background="@color/light_grey" 
       app:bb_activeTabColor="@color/ap_yellow" 
       app:bb_inActiveTabColor="@color/ap_black" 
       app:bb_tabXmlResource="@xml/profile_bar_tabs" 
       app:layout_constraintLeft_toLeftOf="parent" 
       app:layout_constraintRight_toRightOf="parent" 
       app:layout_constraintTop_toBottomOf="@+id/tv_followers"/> 

      <TextView 
       android:id="@+id/tv_history" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="50dp" 
       android:layout_marginStart="50dp" 
       android:text="@string/tv_history" 
       app:layout_constraintLeft_toLeftOf="parent" 
       app:layout_constraintTop_toBottomOf="@+id/number_history"/> 

      <TextView 
       android:id="@+id/tv_followers" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/tv_followers" 
       app:layout_constraintLeft_toLeftOf="@+id/tv_history" 
       app:layout_constraintRight_toRightOf="@+id/tv_following" 
       app:layout_constraintTop_toBottomOf="@+id/number_followers"/> 

      <TextView 
       android:id="@+id/tv_following" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginEnd="40dp" 
       android:layout_marginRight="40dp" 
       android:text="@string/tv_following" 
       app:layout_constraintRight_toRightOf="parent" 
       app:layout_constraintTop_toBottomOf="@+id/number_following"/> 

      <TextView 
       android:id="@+id/number_history" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="20dp" 
       android:text="@string/test_history" 
       android:textStyle="bold" 
       app:layout_constraintEnd_toEndOf="@id/tv_history" 
       app:layout_constraintLeft_toLeftOf="parent" 
       app:layout_constraintStart_toStartOf="@id/tv_history" 
       app:layout_constraintTop_toBottomOf="@+id/view"/> 

      <TextView 
       android:id="@+id/number_followers" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="20dp" 
       android:text="@string/test_followers" 
       android:textStyle="bold" 
       app:layout_constraintLeft_toLeftOf="@+id/number_history" 
       app:layout_constraintRight_toRightOf="@+id/number_following" 
       app:layout_constraintTop_toBottomOf="@+id/view"/> 

      <TextView 
       android:id="@+id/number_following" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="20dp" 
       android:text="@string/test_following" 
       android:textStyle="bold" 
       app:layout_constraintEnd_toEndOf="@id/tv_following" 
       app:layout_constraintRight_toRightOf="parent" 
       app:layout_constraintStart_toStartOf="@id/tv_following" 
       app:layout_constraintTop_toBottomOf="@+id/view"/> 


     </android.support.constraint.ConstraintLayout> 

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

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/rv_grid" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scrollbars="none" 
     android:visibility="visible" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

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

+0

根據我的建議,在點擊按鈕時用所需的佈局初始化新的適配器對象。 –

+0

@RahulSharma但是我怎麼會仍然有'header'? – Esteban

+0

將所需的標題添加到新適配器,因爲您現在正在執行 –

回答

1

編輯:

如果您需要確切的Instagram的設計,請看看這個Sample

當你在標籤按鈕點擊,只需使用hide並顯示vi並且把兩者分開的佈局管理器。

private boolean gridClick = false; 


    case R.id.list_click:      

       if(listClick) {     // Check whether the tab is already clicked or not 

        Log.e("AlreadyClicked", "Test"); 

       } else { 

        Log.e("ClickedFirstTime", "Test"); 

        loadPost(); 

        ivGrid.setVisibility(View.GONE);  // Hiding grid recyclerview 
        ivList.setVisibility(View.VISIBLE); // showing list recyclerview 

        rvGrid.setVisibility(View.GONE);  // Make grid recyclerview as gone 
        recyclerList.setVisibility(View.VISIBLE); // make listview as visible 



        RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(this);  // Use separate layoutmanager for list recyclerview 

        recyclerList.setLayoutManager(mLayoutManager); 
        recyclerList.setItemAnimator(new DefaultItemAnimator()); 
        recyclerList.setAdapter(friendsProfileUserPostitemsAdapter); 

        listClick = true; 


       } 

       break; 
+0

嗯,我無法訪問這些列表,因爲它們位於不同的活頁夾中。根據您的解決方案,我需要在第一個文件夾中隱藏/顯示第二個文件夾中的項目。 – Esteban

+0

@Esteban我已經做過instagram設計。你可以簡單地用4或5個按鈕進行單個活動。只需隱藏並顯示相應的視圖。您需要像[this]這樣的用戶協調器佈局(http:// stackoverflow。 com/a/40182035/3960700)。不要使用嵌套的滾動視圖。它在回收站查看方式不好。 – Steve

+0

@Esteban檢查我編輯過的文章。當你運行這個樣本時,你可以得到一些清晰的標識。 – Steve

1

我覺得你做錯了實現。不需要在RecyclerView項目中添加TabLayout。

你的代碼應該是這樣的

<android.support.design.widget.CoordinatorLayout> 
    <android.support.design.widget.AppBarLayout> 
      <android.support.design.widget.CollapsingToolbarLayout> 

       <YourHeaderLayout /> 
       <android.support.design.widget.TabLayout />    

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

    <RecyclerView /> 
    <!-- OR --> 
    <ViewPager /> 


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

這裏如果顯示RecyclerView那麼你需要改變分頁上按佈局管理。或者您可以將兩個RecyclerView與列表和網格在ViewPager

+0

有沒有辦法做到這一點,而不需要'CollapsingToolbarLayout?'我需要內容滾動 - Instagram的用戶個人資料頁面 – Esteban

+0

您可以在不使用CollapsingToolbarLayout的情況下使用AppBarLayout,而對於滾動,您可以android.support.v4.widget.NestedScrollView。 –

+0

@Esteban不會收到。您想說關於滾動標題的內容? –

相關問題