效果:
实现方法
1、layout文件结构
最外部使用相对布局
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context=".MainActivity">
布局最下面添加头部下拉可隐藏view
<LinearLayoutandroid:id="@+id/mmm"android:layout_width="match_parent"android:layout_height="50dp"android:orientation="horizontal"android:background="@color/colorPrimaryDark"><TextViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:textColor="@color/colorAccent"android:textSize="18dp"android:text="可开关——下拉view"/></LinearLayout></RelativeLayout>
2、activity实现下拉显示与隐藏
1、实例化
private LinearLayout mNumberLayout;private int mTranslationY = 0;
mNumberLayout = (LinearLayout) findViewById(R.id.mmm);
2、显示,隐藏、两个方法
private void showNumberView() {ViewHelper.setAlpha(mNumberLayout, 0);ViewHelper.setTranslationY(mNumberLayout,mTranslationY - mNumberLayout.getHeight());ViewPropertyAnimator.animate(mNumberLayout).alpha(1f).translationY(mTranslationY).setInterpolator(new DecelerateInterpolator()).setDuration(300).setStartDelay(0).setListener(new CustomAnimatorListener(){@Overridepublic void onAnimationEnd(Animator animator){}}).start(); }private void hideNumberView() {ViewPropertyAnimator.animate(mNumberLayout).alpha(0f).translationY(-mNumberLayout.getHeight() + mTranslationY).setInterpolator(new AccelerateInterpolator()).setDuration(300).setListener(new CustomAnimatorListener(){@Overridepublic void onAnimationEnd(Animator animator){}}).start();}
3、点击方法
private boolean ifshow;
layout_bottom_bar.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {if (ifshow){showNumberView();ifshow=!ifshow;}else {hideNumberView();ifshow=!ifshow;}} });