DrawerLayout above a SurfaceView that was set setZOrderOnTop(true) - android

I have a SurfaceView that should be set with setZOrderOnTop(true) , is it possible to have a DrawerLayout that opens over it. currently the surface draws over the drawer.

In a similar situation the solution from DrawerLayout not working with Android 4.4 & SurfaceView worked for me:
#Override
public void onDrawerSlide(View drawerView, float slideOffset)
{
mDrawerLayout.bringChildToFront(drawerView);
mDrawerLayout.requestLayout();
}
Inside of your DrawerListener

The below code worked for me.
actionBarDrawerToggle = new ActionBarDrawerToggle(this,drawerLayout,R.string.open, R.string.close)
{
#Override
public void onDrawerSlide(View drawerView, float slideOffset) {
super.onDrawerSlide(drawerView, slideOffset);
drawerLayout.bringChildToFront(drawerView);
drawerLayout.requestLayout();
}
};

Related

Raw use of parameterized class on Android Studio

I have this code on my Android project:
final BottomSheetBehavior infoBottomSheetBehavior = BottomSheetBehavior.from(findViewById(R.id.info_view));
infoBottomSheetBehavior.addBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
#Override
public void onStateChanged(#NonNull View bottomSheet, int newState) {
if (newState == BottomSheetBehavior.STATE_DRAGGING) {
infoBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}
}
#Override
public void onSlide(#NonNull View bottomSheet, float slideOffset) {
}
});
And the next warning appears over BottomSheetBehavior: Raw use of parameterized class 'BottomSheetBehavior'
Does anybody know how to avoid this warning?
Ok, here is the so basic answer from a coffee talk...
final BottomSheetBehavior<View> infoBottomSheetBehavior = BottomSheetBehavior.from(findViewById(R.id.info_view));
infoBottomSheetBehavior.addBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
#Override
public void onStateChanged(#NonNull View bottomSheet, int newState) {
if (newState == BottomSheetBehavior.STATE_DRAGGING) {
infoBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}
}
#Override
public void onSlide(#NonNull View bottomSheet, float slideOffset) {
}
});
I've just missed the <View>

How to keep my navigation drawer always below my content?

I have a navigation drawer in my App. When I open the drawer I want it to open below the content, I changed some attributes to get the image what I have. but what I want is show in image What I want to reach, and you can find my code here:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
final CoordinatorLayout content = (CoordinatorLayout) findViewById(R.id.content);
drawerLayout.setScrimColor(Color.TRANSPARENT);
ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar,R.string.navigation_drawer_open, R.string.navigation_drawer_close) {
private float scaleFactor = 6f;// private float scaleFactor = 6f;
#Override
public void onDrawerSlide(View drawerView, float slideOffset) {
super.onDrawerSlide(drawerView, slideOffset);
float slideX = drawerView.getWidth() * slideOffset;
content.setTranslationX(slideX);
content.setScaleX(1 );
content.setScaleY(1 - (slideOffset / scaleFactor));
}
};
drawerLayout.setScrimColor(Color.TRANSPARENT);
drawerLayout.setDrawerElevation(0f);
drawerLayout.addDrawerListener(actionBarDrawerToggle);

How to fix the expanded height of umano slidingpanellayout

I am trying to fix the expanded height of the sliding panel. What I want is that the sliding panel layout can be expanded only to 40 or 50% of screen height. I tried adding umanoAnchorPoint attribute with value 0.4 but the view can still be dragged to full screen.
You may use the sliding listener like this:
slidingUpPanelLayout.addPanelSlideListener(new SlidingUpPanelLayout.PanelSlideListener() {
#Override
public void onPanelSlide(View panel, float slideOffset) {
}
#Override
public void onPanelStateChanged(View panel, SlidingUpPanelLayout.PanelState previousState, SlidingUpPanelLayout.PanelState newState) {
if(newState == SlidingUpPanelLayout.PanelState.EXPANDED) slidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.ANCHORED);
}
});
or maybe:
slidingUpPanelLayout.addPanelSlideListener(new SlidingUpPanelLayout.PanelSlideListener() {
#Override
public void onPanelSlide(View panel, float slideOffset) {
if(slideOffset > desiredOffset) slidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.ANCHORED);
}
#Override
public void onPanelStateChanged(View panel, SlidingUpPanelLayout.PanelState previousState, SlidingUpPanelLayout.PanelState newState) {
}
});

Android ActionBarDrawerToggle onDrawerClosed called after delay

I have an app where I override the onDrawerClosed of an ActionBarDrawerToggle. I have noticed that there is always an unwanted delay before the onDrawerClosed method is called. The problem is very easy to spot: when I override onDrawerSlide and put in some logging I see clearly that the slideOffset value is 0.0 somewhere between 50-100ms before onDrawerClosed is called. Why is this delay there?
mDrawerToggle = new ActionBarDrawerToggle([...]) {
public void onDrawerClosed(View view) {
Log.d(TAG, String.format("% 12d onDrawerClosed", Calendar.getInstance().getTimeInMillis()));
super.onDrawerClosed(view);
}
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
#Override
public void onDrawerSlide(View drawerView, float slideOffset) {
Log.d(TAG, String.format("% 12d onDrawerSlide %f", Calendar.getInstance().getTimeInMillis(), slideOffset)));
// THIS IS CALLED WITH slideOffset = 0.0f TOO LONG BEFORE onDrawerClosed
super.onDrawerSlide(drawerView, slideOffset);
}
};
i'm not sure about this answer can you put that Log.d after super invoked

Navigation Drawer move whole screen

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?
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.
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));

Categories

Resources