该库是 MaterialUp.com 上发布的过滤器概念的实现。
它使得FloatingActionButton到BottomSheetDialog的动画很容易实现。
摇篮
将依赖项添加到应用程序级 build.gradle 文件:
dependencies {
implementation ' io.github.krupen:fabulousfilter:0.0.6 '
}
创建一个扩展AAH_FabulousFragment
的片段:
public class MySampleFabFragment extends AAH_FabulousFragment {
public static MySampleFabFragment newInstance() {
MySampleFabFragment f = new MySampleFabFragment();
return f;
}
@Override
public void setupDialog(Dialog dialog, int style) {
View contentView = View.inflate(getContext(), R.layout.filter_sample_view, null);
RelativeLayout rl_content = (RelativeLayout) contentView.findViewById(R.id.rl_content);
LinearLayout ll_buttons = (LinearLayout) contentView.findViewById(R.id.ll_buttons);
contentView.findViewById(R.id.btn_close).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
closeFilter("closed");
}
});
//params to set
setAnimationDuration(600); //optional; default 500ms
setInterpolator(new AccelerateDecelerateInterpolator()); // optional
setPeekHeight(300); // optional; default 400dp
setCallbacks((Callbacks) getActivity()); //optional; to get back result
setAnimationListener((AnimationListener) getActivity()); //optional; to get animation callbacks
setViewgroupStatic(ll_buttons); // optional; layout to stick at bottom on slide
setViewPager(vp_types); //optional; if you use viewpager that has scrollview
setViewMain(rl_content); //necessary; main bottomsheet view
setMainContentView(contentView); // necessary; call at end before super
super.setupDialog(dialog, style); //call super at last
}
}
为具有父元素AAH_FilterView
的片段创建视图:
<com.allattentionhere.fabulousfilter.AAH_FilterView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/rl_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:background="@color/orange"
android:visibility="invisible"
tools:ignore="MissingPrefix"
tools:visibility="visible">
<LinearLayout
android:id="@+id/ll_buttons"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_alignParentBottom="true"
android:background="@color/brown"
android:orientation="horizontal"
android:weightSum="2">
</LinearLayout>
</RelativeLayout>
</com.allattentionhere.fabulousfilter.AAH_FilterView>
单击 FloatingActionButton 启动片段,如下所示:
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MySampleFabFragment dialogFrag = MySampleFabFragment.newInstance();
dialogFrag.setParentFab(fab);
dialogFrag.show(getSupportFragmentManager(), dialogFrag.getTag());
}
});
该参数指定动画结束后显示的底部表单的ViewGroup。它可以是任何 ViewGroup(LinearLayout/FrameLayout 等):
setViewMain(relativelayout_content);
此参数指定对话框的膨胀视图:
setMainContentView(contentDialogView);
此参数设置平移和缩放动画的动画持续时间(以milliseconds
为单位):
setAnimationDuration(600); // default 500ms
该参数用于设置 fab 动画的插值器:
setInterpolator(new AccelerateDecelerateInterpolator());
此参数设置底部工作表的窥视高度(以dp
为单位):
setPeekHeight(300); // default 400dp
此参数用于从AAH_FabulousFragment
获取调用它的组件的回调:
setCallbacks((Callbacks) getActivity());
要使用它,请在调用组件(Activity/Fragment 等)中实现回调,例如:
public class MainSampleActivity extends AppCompatActivity implements AAH_FabulousFragment.Callbacks {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_sample);
}
@Override
public void onResult(Object result) {
if (result.toString().equalsIgnoreCase("swiped_down")) {
//do something or nothing
} else {
//handle result
}
}
}
该参数用于获取动画回调。
setAnimationListener((AnimationListener) getActivity());
要使用它,请在调用组件(Activity/Fragment 等)中实现 AnimationListener,例如:
public class MainSampleActivity extends AppCompatActivity implements AAH_FabulousFragment.AnimationListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_sample);
}
@Override
public void onOpenAnimationStart() {
//do something on open animation start
}
@Override
public void onOpenAnimationEnd() {
//do something on open animation end
}
@Override
public void onCloseAnimationStart() {
//do something on close animation start
}
@Override
public void onCloseAnimationEnd() {
//do something on close animation start
}
}
该参数用于使底部工作表中的视图在用户滑动时保持静态。它可以是任何 ViewGroup(LinearLayout/FrameLayout 等):
setViewgroupStatic(linearlayout_buttons);
此参数用于支持 ViewPager 中的滚动,因为 BottomSheetDialog 不支持滚动的多个视图:
setViewPager(viewPager);
版权所有 2017 克鲁彭·盖蒂亚
根据 Apache 许可证 2.0 版(“许可证”)获得许可;除非遵守许可证,否则您不得使用此文件。您可以在以下位置获取许可证副本:
http://www.apache.org/licenses/LICENSE-2.0
除非适用法律要求或书面同意,否则根据许可证分发的软件均按“原样”分发,不带任何明示或暗示的保证或条件。请参阅许可证,了解许可证下管理权限和限制的特定语言。