android中控件底部显示,BottomSheet是一个Android组件实现从屏幕底部显示一个 dismissible 视图...

BottomSheet

68747470733a2f2f7472617669732d63692e6f72672f466c6970626f6172642f626f74746f6d73686565742e73766768747470733a2f2f6261646765732e6769747465722e696d2f4a6f696e253230436861742e737667

BottomSheet is an Android component which presents a dismissible view from the bottom of the screen. BottomSheet can be a useful replacement for dialogs and menus but can hold any view so the use cases are endless. This repository includes the BottomSheet component itself but also includes a set of common view components presented in a bottom sheet. These are located in the commons module.

BottomSheet has been used in production at Flipboard for a while now so it is thoroughly tested. Here is a GIF of it in action inside of Flipboard!

6befea4ee671b6cbf09fc649508731c4.gif

Installation

If all you want is the BottomSheet component and don't need things from commons you can skip that dependency.

repositories {

jcenter()

}

dependencies {

compile 'com.flipboard:bottomsheet-core:1.5.3'

compile 'com.flipboard:bottomsheet-commons:1.5.3' // optional

}

Getting Started

Get started by wrapping your layout in a BottomSheetLayout. So if you currently have this:

android:id="@+id/root"

android:orientation="vertical"

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/view1"

android:layout_width="match_parent"

android:layout_height="match_parent"/>

You would have to update it to look like this:

android:id="@+id/bottomsheet"

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/root"

android:orientation="vertical"

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/view1"

android:layout_width="match_parent"

android:layout_height="match_parent"/>

Back in your activity or fragment you would get a reference to the BottomSheetLayout like any other view.

BottomSheetLayout bottomSheet = (BottomSheetLayout) findViewById(R.id.bottomsheet);

Now all you need to do is show a view in the bottomSheet:

bottomSheet.showWithSheetView(LayoutInflater.from(context).inflate(R.layout.my_sheet_layout, bottomSheet, false));

You could also use one of the sheet views from the commons module.

bottomSheet.showWithSheetView(new IntentPickerSheetView(this, shareIntent, "Share with...", new IntentPickerSheetView.OnIntentPickedListener() {

@Override

public void onIntentPicked(IntentPickerSheetView.ActivityInfo activityInfo) {

bottomSheet.dismissSheet();

startActivity(activityInfo.getConcreteIntent(shareIntent));

}

}));

That's it for the simplest of use cases. Check out the API documentation to find out how to customize BottomSheet to fit your use cases.

For more examples, also see the Recipes wiki.

Common Components

These are located in the optional bottomsheet-commons dependency and implement common use cases for bottom sheet.

Intent Picker

Menu Sheet

ImagePicker Sheet

0f5ba9c82905b544b57b00b6fcdd97d7.gif

1325144e17f515e178cd5a700989b72c.gif

59f076459705c7228cd8a082024c2345.gif

IntentPickerSheetView

This component presents an intent chooser in the form of a BottomSheet view. Give it an intent such as a share intent and let the user choose what activity they want to share the intent with in a BottomSheet.

Example from the sample app.

IntentPickerSheetView intentPickerSheet = new IntentPickerSheetView(MainActivity.this, shareIntent, "Share with...", new IntentPickerSheetView.OnIntentPickedListener() {

@Override

public void onIntentPicked(IntentPickerSheetView.ActivityInfo activityInfo) {

bottomSheet.dismissSheet();

startActivity(activityInfo.getConcreteIntent(shareIntent));

}

});

// Filter out built in sharing options such as bluetooth and beam.

intentPickerSheet.setFilter(new IntentPickerSheetView.Filter() {

@Override

public boolean include(IntentPickerSheetView.ActivityInfo info) {

return !info.componentName.getPackageName().startsWith("com.android");

}

});

// Sort activities in reverse order for no good reason

intentPickerSheet.setSortMethod(new Comparator() {

@Override

public int compare(IntentPickerSheetView.ActivityInfo lhs, IntentPickerSheetView.ActivityInfo rhs) {

return rhs.label.compareTo(lhs.label);

}

});

bottomSheet.showWithSheetView(intentPickerSheet);

MenuSheetView

This component presents a BottomSheet view that's backed by a menu. It behaves similarly to the new NavigationView in the Design support library, and is intended to mimic the examples in the Material Design spec. It supports list and grid states, with the former adding further support for separators and subheaders.

Example from the sample app.

MenuSheetView menuSheetView =

new MenuSheetView(MenuActivity.this, MenuSheetView.MenuType.LIST, "Create...", new MenuSheetView.OnMenuItemClickListener() {

@Override

public boolean onMenuItemClick(MenuItem item) {

Toast.makeText(MenuActivity.this, item.getTitle(), Toast.LENGTH_SHORT).show();

if (bottomSheetLayout.isSheetShowing()) {

bottomSheetLayout.dismissSheet();

}

return true;

}

});

menuSheetView.inflateMenu(R.menu.create);

bottomSheetLayout.showWithSheetView(menuSheetView);

Contributing

We welcome pull requests for bug fixes, new features, and improvements to BottomSheet. Contributors to the main BottomSheet repository must accept Flipboard's Apache-style Individual Contributor License Agreement (CLA) before any changes can be merged.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值