2016-07-31 17 views
1

我想使用模式底部片。材料設計指南說,完全展開的底部表單應該在操作欄下方8dp。我怎樣才能做到這一點?我想在操作欄中保留一個X標記以在完全展開時關閉底部表格。Modal底部表單:如何從動作欄設置8dp?

當我嘗試使用linearLayout底部表單時,狀態展開時會佔用整個屏幕。

我bottomsheet佈局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:elevation="@dimen/design_bottom_sheet_modal_elevation" 
android:orientation="vertical"> 


<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"/> 


<Button 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:layout_marginRight="10dp" 
    android:layout_marginLeft="10dp" 
    android:layout_marginTop="10dp" 
    android:layout_marginBottom="10dp" 
    android:text="ADD"/> 

</LinearLayout> 
+0

您能告訴我您的XML嗎? –

+0

@abat,你有沒有設法實現這個? – jzarsuelo

+0

@jzarsuelo:看到我的答案 – abat

回答

0

我沒有找到一個簡單的方法,但這裏是我做過什麼。我測量了狀態欄和操作欄的高度,並從屏幕高度中減去了高度。適合我。不知道這是否是最好的方法。 `

private int getBottomSheetMaximumHeight() { 
     // get toolbar height 
     Toolbar toolbar = (Toolbar) getActivity().findViewById(R.id.toolbar); 
     int toolbarHeight = toolbar.getHeight(); 

     //get status bar height 
     Rect rectangle = new Rect(); 
     Window window = getActivity().getWindow(); 
     window.getDecorView().getWindowVisibleDisplayFrame(rectangle); 
     int windowHeight = rectangle.bottom; 

     // material design recommended bottomsheet padding from actionbar 
     final int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,8, getContext().getResources().getDisplayMetrics()); 

     // maximum height of the bottomsheet 
     return windowHeight - toolbarHeight - rectangle.top - padding; 

    }` 
相關問題