Reputation: 181
I'm trying to make Navigation Drawer which moves whole screen (whole height, not width). I'm not using ActionBar and other libraries, just default Android drawer. Anyone have any examples?
Upvotes: 0
Views: 784
Reputation: 8293
Implements DrawerListener (passing as parameter the R.id of your layout):
import android.animation.ObjectAnimator;
import android.support.v4.widget.DrawerLayout.DrawerListener;
import android.view.View;
public class DrawerLayoutListener implements DrawerListener {
private View _contentDrawer;
private int _idView;
public DrawerLayoutListener(int idView) {
_idView = idView;
}
@Override
public void onDrawerClosed(View arg0) {}
@Override
public void onDrawerOpened(View arg0) {}
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
if (_contentDrawer == null) _contentDrawer = ((View) drawerView.getParent()).findViewById(_idView);
float moveFactor = (drawerView.getWidth() * slideOffset);
ObjectAnimator.ofFloat(_contentDrawer, "translationX", moveFactor).setDuration(0).start();
}
@Override
public void onDrawerStateChanged(int arg0) {}
}
And set it as listener to your DrawerLayout
:
drawer_layout.setDrawerListener(new DrawerLayoutListener(R.id.content_frame));
Upvotes: 1
Reputation: 11190
What you need to do is to set the translationX property of your content view by the pixel amount the drawer has moved to.
In your implementation of http://developer.android.com/reference/android/support/v4/widget/DrawerLayout.DrawerListener.html you should implement onDrawerSlide(View drawerView, float slideOffset)
.
In this method you should add this line.
mDrawerLayout.findViewById(R.id.your_content_id).setTranslationX(drawerView.getWidth() * slideOffset);
That should do the trick.
Upvotes: 2