android 上下抽屉拖拽+动画完美实现

效果绝对满足
1.导入依赖

dependencies {

    implementation 'com.github.moraisigor:slidingdrawer:1.7.1'
}

2.布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:layout="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#f1582a">
    
    <hollowsoft.slidingdrawer.SlidingDrawer
        android:id="@+id/drawer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        layout:content="@+id/content"
        layout:handle="@+id/handle">
        
        <TextView
            android:id="@id/handle"
            android:layout_width="match_parent"
            android:layout_height="75dp"
            android:background="#122631"
            android:gravity="center"
            android:text="Handle"
            android:textAllCaps="true"
            android:textColor="@android:color/white"
            android:textSize="20sp"
            android:textStyle="bold" />
            
        <TextView
            android:id="@+id/content"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="Content"
            android:textAllCaps="true"
            android:textColor="@android:color/white"
            android:textSize="20sp"
            android:textStyle="bold" />
            
    </hollowsoft.slidingdrawer.SlidingDrawer>
    
</LinearLayout>

3.类

public final class MainActivity extends AppCompatActivity implements OnDrawerScrollListener, OnDrawerOpenListener, OnDrawerCloseListener {
                                                
    private static final String TAG = MainActivity.class.getSimpleName();
    
    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        
        setContentView(R.layout.main);
        
        final SlidingDrawer drawer = (SlidingDrawer) findViewById(R.id.drawer);

        drawer.setOnDrawerScrollListener(this);
        drawer.setOnDrawerOpenListener(this);
        drawer.setOnDrawerCloseListener(this);
    }
    
    @Override
    public void onScrollStarted() {
        Log.d(TAG, "onScrollStarted()");
    }

    @Override
    public void onScrollEnded() {
        Log.d(TAG, "onScrollEnded()");
    }

    @Override
    public void onDrawerOpened() {
        Log.d(TAG, "onDrawerOpened()");
    }

    @Override
    public void onDrawerClosed() {
        Log.d(TAG, "onDrawerClosed()");
    }
}

你可能感兴趣的:(自定义view,android,studio,android)