
compile 'com.android.support:design:'
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.mayojava.sample.bottomsheetdemo.MainActivity">
<!-- main content layout-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
......
</RelativeLayout>
<!-- bottom sheet layout -->
<RelativeLayout
android:id="@+id/linear_layout_bottom_sheet"
android:layout_width="match_parent"
android:layout_height="220dp"
app:behavior_peekHeight="80dp"
app:behavior_hideable="true"
app:layout_behavior="@string/string_bottom_sheet_behavior"
android:elevation="@dimen/z_bottom_sheet"
android:background="@color/color_bottom_sheet">
<TextView
android:id="@+id/text_view_sheet_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/text_pull_to_show_more"
android:textSize="@dimen/text_size_medium"
android:padding="@dimen/activity_vertical_margin"/>
<TextView
android:id="@+id/text_view_more_content"
android:text="@string/text_more_contet_to_user"
android:textSize="@dimen/text_size_big"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/text_view_sheet_title"
android:paddingLeft="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_vertical_margin"/>
<Button
android:text="@string/text_click_me"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="@dimen/activity_vertical_margin"
android:layout_marginRight="@dimen/activity_vertical_margin"
android:layout_marginTop="@dimen/activity_vertical_margin" android:layout_below="@+id/text_view_more_content"/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
LinearLayout bottomSheetLayout
= (LinearLayout) findViewById(R.id.layout_bottom_sheet);
//get bottom sheet behavior from bottom sheet view
BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(mLayoutBottomSheet);
- BottomSheetBehavior.STATE_EXPANDED : باتم شیت را به طور کامل باز می کند.
- BottomSheetBehavior.STATE_HIDE باتم شیت را به طور کامل از دید خارج می کند.
- BottomSheetBehavior.STATE_COLLAPSED ارتفاع باتم شیت را به همراه با تنظیم آن در اتریبیوت peekHeight .
//to expand the bottom sheet mbottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); //to collapse the bottom sheet mbottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
);mbottomSheetBehavior.setPeekHeight(320);
ساخت یک مدل باتم شیت
مدل باتم شیت یک دیالوگ همراه با رفتار باتم شیت می باشد، و همچنین قسمتی از هایراکی ویو شما نیست. می تواند به عنوان منوی جایگزین استفاده شود، انتخاب کننده محتوا یا یه عنوان یک دیالوگ ساده در اپلیکیشن شما باشد.
Create a class that extends BottomSheetDialogFragment, inflated with the layout that will be used as the content of the modal dialog.
یک کلاس بسازید که از BottomSheetDialogFragment اکستند(extends ) شده باشد، لی اوت را inflated کرده که در اینجا به عنوان محتوای مدل دیالوگ ما استفاده می شود.
layout_custom_bottom_sheet.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<ImageView
android:id="@+id/ic_image"
android:src="@mipmap/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/margin_normal"
android:layout_marginTop="@dimen/activity_vertical_margin"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello bottom sheet"
android:textSize="@dimen/text_size_medium"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_toRightOf="@+id/ic_image"
android:layout_alignTop="@+id/ic_image"/>
<TextView
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_below="@+id/ic_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text_lorem_ipsum"
android:lineSpacingExtra="@dimen/margin_small"
android:layout_marginBottom="@dimen/margin_normal"/>
</RelativeLayout>
CustomBottomSheetDialog bottomSheetDialog = CustomBottomSheetDialog.getInstance(); bottomSheetDialog.show(getSupportFragmentManager(), "Custom Bottom Sheet");








