Which layout component is the right one for building a drawer menu with icons that are always visible? I don't want to use a SlidingPaneLayout
because the main content should not be affected by this.
Asked
Active
Viewed 514 times
2

Markus Palme
- 659
- 4
- 15
-
1If you explain you problem more clearly, it would helped... – Murtaza Khursheed Hussain Nov 23 '15 at 08:22
1 Answers
3
1. Add CrossFadeSlidingPaneLayout
public class CrossFadeSlidingPaneLayout extends SlidingPaneLayout {
private View partialView = null;
private View fullView = null;
// helper flag pre honeycomb used in visibility and click response handling
// helps avoid unnecessary layouts
private boolean wasOpened = false;
public CrossFadeSlidingPaneLayout(Context context) {
super(context);
}
public CrossFadeSlidingPaneLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CrossFadeSlidingPaneLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
if (getChildCount() < 1) {
return;
}
View panel = getChildAt(0);
if (!(panel instanceof ViewGroup)) {
return;
}
ViewGroup viewGroup = (ViewGroup) panel;
if (viewGroup.getChildCount() != 2) {
return;
}
fullView = viewGroup.getChildAt(0);
partialView = viewGroup.getChildAt(1);
super.setPanelSlideListener(crossFadeListener);
}
@Override
public void setPanelSlideListener(final PanelSlideListener listener) {
if (listener == null) {
super.setPanelSlideListener(crossFadeListener);
return;
}
super.setPanelSlideListener(new PanelSlideListener() {
@Override
public void onPanelSlide(View panel, float slideOffset) {
crossFadeListener.onPanelSlide(panel, slideOffset);
listener.onPanelSlide(panel, slideOffset);
}
@Override
public void onPanelOpened(View panel) {
listener.onPanelOpened(panel);
}
@Override
public void onPanelClosed(View panel) {
listener.onPanelClosed(panel);
}
});
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
if (partialView != null) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
// "changed" means that views were added or removed
// we need to move the partial view out of the way in any case (if it's supposed to of course)
updatePartialViewVisibilityPreHoneycomb(isOpen());
} else {
partialView.setVisibility(isOpen() ? View.GONE : VISIBLE);
}
}
}
private SimplePanelSlideListener crossFadeListener = new SimplePanelSlideListener() {
@Override
public void onPanelSlide(View panel, float slideOffset) {
super.onPanelSlide(panel, slideOffset);
if (partialView == null || fullView == null) {
return;
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
if (slideOffset == 1 && !wasOpened) {
// the layout was just opened, move the partial view off screen
updatePartialViewVisibilityPreHoneycomb(true);
wasOpened = true;
} else if (slideOffset < 1 && wasOpened) {
// the layout just started to close, move the partial view back, so it can be shown animating
updatePartialViewVisibilityPreHoneycomb(false);
wasOpened = false;
}
} else {
partialView.setVisibility(isOpen() ? View.GONE : VISIBLE);
}
ViewHelper.setAlpha(partialView, 1 - slideOffset);
ViewHelper.setAlpha(fullView, slideOffset);
}
};
private void updatePartialViewVisibilityPreHoneycomb(boolean slidingPaneOpened) {
// below API 11 the top view must be moved so it does not consume clicks intended for the bottom view
// this applies curiously even when setting its visibility to GONE
// this might be due to platform limitations or it may have been introduced by NineOldAndroids library
if (slidingPaneOpened) {
partialView.layout(-partialView.getWidth(), 0, 0, partialView.getHeight());
} else {
partialView.layout(0, 0, partialView.getWidth(), partialView.getHeight());
}
}
}
2. layout of activity
<com.xxx.CrossFadeSlidingPaneLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/sliding_pane_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="@dimen/side_pane_width"
android:layout_height="match_parent"
android:background="@color/purple">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="7dp"
android:background="@drawable/ic_launcher" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Your Screen" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="7dp"
android:background="@drawable/ic_launcher" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Your Screen" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="7dp"
android:background="@drawable/ic_launcher" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Your Screen" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="55dp"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@drawable/ic_launcher" />
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@drawable/ic_launcher" />
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@drawable/ic_launcher" />
</LinearLayout>
</FrameLayout>
<TextView
android:layout_width="@dimen/main_pane_width"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/partial_pane_width"
android:layout_weight="1"
android:background="@color/light_blue"
android:text="@string/pane_2" />
</com.xxx.CrossFadeSlidingPaneLayout>
its done now always menu will be visible :)
Attribution to original project: Github Url

Parag Chauhan
- 35,760
- 13
- 86
- 95
-
With that layout, the icons are visible so it's a good start. However, it does not allow to expand the menu. Or did I miss anything? – Markus Palme Nov 24 '15 at 09:39
-