I created this sliding drawer to counter the many sliding drawers that are architectured as a ViewGroup that can have only 2 children. The 1st one is the non slidable view; the 2nd is the slidable view, which can slide over the non slidable view.
There are major disadvantages to this. My sliding drawer has no such limitations. And another substantial difference from all other implementations is that it is easy to position the slidable view relative to any view. My sliding drawer can hide content out of the screen and allow the user to drag a handle to bring the content on screen. Currently this drawer is meant only for vertical orientations. The size of the sliding drawer can be defined, an offset can be set, the drawer can take on any shape, content and/or child views.
More Android Developer Documentation :)
Add this to your dependencies:
dependencies {
implementation project(':drxenocustomlayout')
}
<?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="#FFFFFF">
<com.blog.ljtatum.drxenocustomlayout.gui.CustomDrawerLayout
android:id="@+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="500dp" >
</com.blog.ljtatum.drxenocustomlayout.gui.CustomDrawerLayout>
</LinearLayout>
public class MainActivity extends AppCompatActivity {
private CustomDrawerLayout mCustomDrawerLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mCustomDrawerLayout = (CustomDrawerLayout) findViewById(R.id.sliding_layout);
mCustomDrawerLayout.toggleGlobalTouchEvent(true);
mCustomDrawerLayout.setDefaultLockMode(CustomDrawerLayout.LockMode.LOCK_MODE_OPEN);
// initialize listeners
initializeListeners();
}
/**
* Initialize custom listeners
*/
private void initializeListeners() {
// OnInteractListener for drawer
mCustomDrawerLayout.setOnInteractListener(new CustomDrawerLayout.OnInteractListener() {
@Override
public void onDrawerOpened() {
// do whatever you want when drawer opens
Toast.makeText(MainActivity.this, "drawer opened", Toast.LENGTH_LONG).show();
}
@Override
public void onDrawerClosed() {
// do whatever you want when drawer closes
Toast.makeText(MainActivity.this, "drawer closed", Toast.LENGTH_LONG).show();
}
});
// animate top and bottom views
ViewTreeObserver vto = mCustomDrawerLayout.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
mCustomDrawerLayout.setOffsetHeight(mCustomDrawerLayout.getHeight() / 4);
mCustomDrawerLayout.setDefaultLockMode(CustomDrawerLayout.LockMode.LOCK_MODE_CLOSED);
}
});
}
}
Check the sample for more details.
Copyright (c) 2017 Leonard Tatum. All rights reserved.
Redistribution and use in source and binary forms are permitted provided that
the above copyright notice and this paragraph are duplicated in all such forms
and that any documentation, advertising materials, and other materials related
to such distribution and use acknowledge that the software was developed by
Leonard Tatum. The names of the developers may not be used to endorse or
promote products derived from this software without specific prior written
permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.