Android 模式底页:如何从操作栏设置8dp?
我想使用模态底片。材料设计指南规定,完全展开的底板应低于活动杆8dp。我怎样才能做到这一点?我想在操作栏中保留一个Android 模式底页:如何从操作栏设置8dp?,android,material-design,bottom-sheet,Android,Material Design,Bottom Sheet,我想使用模态底片。材料设计指南规定,完全展开的底板应低于活动杆8dp。我怎样才能做到这一点?我想在操作栏中保留一个X标记,以便在完全展开时关闭底部页 当我尝试使用linearLayout底片时,当状态展开时,它会占据整个屏幕 我的底图布局 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_hei
X
标记,以便在完全展开时关闭底部页
当我尝试使用linearLayout底片时,当状态展开时,它会占据整个屏幕
我的底图布局
<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>
我没有找到一个简单的方法,但下面是我所做的。我测量了状态栏和操作栏的高度,并从屏幕高度中减去了它们。对我来说很好。不确定这是不是最好的办法
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;
}`
我没有找到一个简单的方法,但我做到了。我测量了状态栏和操作栏的高度,并从屏幕高度中减去了它们。对我来说很好。不确定这是不是最好的办法
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;
}`
你能展示你的XML吗?@abat,你实现了吗?@jzarsuelo:看到我的答案了吗?你能展示你的XML吗?@abat,你实现了吗?@jzarsuelo:看到我的答案了吗