2017-08-16 63 views
0

我有一些RecyclerView位於屏幕的底部和其他視圖的下方。目前,它是水平的,只有1排。當用戶觸摸某個項目時,我想將其展開爲全屏以便更好地查看。而擴大它必須有2列。用戶也可以通過點擊擴展完成後出現的菜單上的返回按鈕返回。如何將RecyclerView展開爲全屏觸摸項目?

我做了什麼? 我找到了StaggeredGridLayoutManager。它允許更改列的數量。 我的問題是什麼?我無法確定是否必須爲此使用其他活動。但我想這是多餘的。我如何在一項活動中實現這一目標?如何處理RecyclerView以上的其他視圖?

回答

1

對於您正在尋找的東西,而不是更具體的,BottomSheet可能是解決方案。請參閱:https://code.tutsplus.com/articles/how-to-use-bottom-sheets-with-the-design-support-library--cms-26031

或者,您可以使用FrameLayout來包含您的RecyclerView和另一個包含所有其他視圖的佈局。將RecyclerView重力設置爲bottom並將其設置爲行的高度(在示例80dp中)。請注意0​​是最後一個元素,所以它在其他元素之上:

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <!-- other views here --> 
    </LinearLayout> 

    <android.support.v7.widget.RecyclerView 
     android:layout_width="match_parent" 
     android:layout_height="80dp" 
     android:layout_gravity="bottom"/> 

</FrameLayout> 
+0

在這個小提示後標記您的答案。我已經學會了如何使用'bottomomsheet',但是如何在擴展完成後隱藏所有東西(位於我的recyclerview下方)在'bottomomsheet'下?通過使用FrameLayout? – abay

+1

由設計庫執行的'BottomSheet'應該照顧它。另一方面,「FrameLayout」是佈局可以重疊的視圖的一種方式('RelativeLayout'也允許重疊,而'LinearLayout'不會)。在這種情況下,重要的一點是,你想要在最上面的元素是最後一個元素,也就是說,繪圖是按照與視圖相同的順序完成的,在我的示例中,首先繪製「LinearLayout」,然後是「RecyclerView」並且它們重疊,因爲父級是「FrameLayout」。希望這可以解決問題。 –