Sliding menu android:
Its very useful for create menu option with easy navigation.Sliding menu android are hidden normally and show when you press the menu button with slide animation.Its very useful to save your page space.In this example you don't need to import any lib. The most of the top application having sliding menu android like gmail,facebook,google plus etc.
You can also develop sliding menu with navigation drawer.
Step1:
This the code for check wether the menu is visible or and execute the slide in or out animation.
if(contentParams.leftMargin == -(menu.getLayoutParams().width)) { // Menu is hidden (slide out parameters) animateFromX = 0; animateToX = (menu.getLayoutParams().width); marginX = 0; menuOpen = true; } else { // Menu is visible (slide in parameter) animateFromX = 0; animateToX = -(menu.getLayoutParams().width); marginX = -(menu.getLayoutParams().width); menuOpen = false; }
slideMenuIn(animateFromX, animateToX, marginX);
//This is the slideMenuIn method for set properties for the animation
public void slideMenuIn(int animateFromX, int animateToX, final int marginX){
slide = new TranslateAnimation(animateFromX, animateToX, 0, 0);
slide.setDuration(300);
slide.setFillEnabled(true);
slide.setAnimationListener(new AnimationListener() {
public void onAnimationEnd(Animation animation) { // Make movement of content permanent after animation has completed
contentParams.setMargins(marginX, 0, 0, 0); // by positioning its left margin
content.setLayoutParams(contentParams);
}
public void onAnimationRepeat(Animation animation) { }
public void onAnimationStart(Animation animation) { }
});
content.startAnimation(slide); // Slide menu in or out
}
Step 2:
In layout you can change the size of the sliding menu width.here ,i have set 150dp for the menu width.
<LinearLayout android:id="@+id/menu" android:layout_width="150dip" android:layout_height="fill_parent" android:background="@android:color/white" android:orientation="vertical" > <TextView android:layout_width="match_parent" android:layout_height="2dip" android:layout_marginTop="50dip" android:background="#000" /> <ListView android:id="@+id/listView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/transparent" android:cacheColorHint="@android:color/transparent" android:divider="@null" android:dividerHeight="2dp" android:fadingEdge="none" android:listSelector="@android:color/transparent" > </ListView> </LinearLayout>
Screenshot:
No comments:
Post a Comment