android - How to do sliding menu from right to left -
i searching sliding example,
but still couldn't find right left sliding example.
please can 1 give sample project sliding menu right left
slide menu can done using animation classes
//declare inside activity private linearlayout slidingpanel; private boolean isexpanded; private displaymetrics metrics; //private listview listview; private relativelayout headerpanel,menupanel; private int panelwidth; private imageview menuviewbutton; framelayout.layoutparams menupanelparameters; framelayout.layoutparams slidingpanelparameters; linearlayout.layoutparams headerpanelparameters ; linearlayout.layoutparams listviewparameters; //initialize inside oncreate metrics = new displaymetrics(); getwindowmanager().getdefaultdisplay().getmetrics(metrics); panelwidth = (int) ((metrics.widthpixels)*0.45); headerpanel = (relativelayout) findviewbyid(r.id.header); headerpanelparameters = (linearlayout.layoutparams) headerpanel.getlayoutparams(); headerpanelparameters.width = metrics.widthpixels; headerpanel.setlayoutparams(headerpanelparameters); menupanel = (relativelayout) findviewbyid(r.id.menupanel); menupanelparameters = (framelayout.layoutparams) menupanel.getlayoutparams(); menupanelparameters.width = panelwidth; menupanel.setlayoutparams(menupanelparameters); slidingpanel = (linearlayout) findviewbyid(r.id.slidingpanel); slidingpanelparameters = (framelayout.layoutparams) slidingpanel.getlayoutparams(); slidingpanelparameters.width = metrics.widthpixels; slidingpanel.setlayoutparams(slidingpanelparameters); //slide panel menuviewbutton = (imageview) findviewbyid(r.id.menuviewbutton); menuviewbutton.setonclicklistener(new onclicklistener() { public void onclick(view v) { if(!isexpanded){ isexpanded = true; //expand new expandanimation(slidingpanel, panelwidth, animation.relative_to_self, 0.0f, animation.relative_to_self, 0.45f, 0, 0.0f, 0, 0.0f); //toast.maketext(getapplicationcontext(), "expand", 0).show(); }else{ isexpanded = false; //collapse new collapseanimation(slidingpanel,panelwidth, translateanimation.relative_to_self, 0.45f, translateanimation.relative_to_self, 0.0f, 0, 0.0f, 0, 0.0f); //toast.maketext(getapplicationcontext(), "collapse", 0).show(); } } }); //collapse animation class public class collapseanimation extends translateanimation implements translateanimation.animationlistener{ private linearlayout slidinglayout; int panelwidth; public collapseanimation(linearlayout layout, int width, int fromxtype, float fromxvalue, int toxtype, float toxvalue, int fromytype, float fromyvalue, int toytype, float toyvalue) { super(fromxtype, fromxvalue, toxtype, toxvalue, fromytype, fromyvalue, toytype, toyvalue); //initialize slidinglayout = layout; panelwidth = width; setduration(400); setfillafter( false ); setinterpolator(new acceleratedecelerateinterpolator()); setanimationlistener(this); //clear left , right margins layoutparams params = (layoutparams) slidinglayout.getlayoutparams(); params.rightmargin = 0; params.leftmargin = 0; slidinglayout.setlayoutparams(params); slidinglayout.requestlayout(); slidinglayout.startanimation(this); //slidinglayout.setbackgroundcolor(); //slidinglayout.setbackgroundcolor(r.string.white); } @override public void onanimationend(animation arg0) { // todo auto-generated method stub } @override public void onanimationrepeat(animation arg0) { // todo auto-generated method stub } @override public void onanimationstart(animation arg0) { // todo auto-generated method stub } } //expande animation class public class expandanimation extends translateanimation implements animation.animationlistener{ private linearlayout slidinglayout; int panelwidth; public expandanimation(linearlayout layout, int width, int fromxtype, float fromxvalue, int toxtype, float toxvalue, int fromytype, float fromyvalue, int toytype, float toyvalue) { super(fromxtype, fromxvalue, toxtype, toxvalue, fromytype, fromyvalue, toytype, toyvalue); //initialize slidinglayout = layout; panelwidth = width; setduration(400); setfillafter( false ); setinterpolator(new acceleratedecelerateinterpolator()); setanimationlistener(this); slidinglayout.startanimation(this); //slidinglayout.setbackgroundcolor(panelwidth); } @override public void onanimationend(animation animation) { // todo auto-generated method stub //create margin , align left layoutparams params = (layoutparams) slidinglayout.getlayoutparams(); params.leftmargin = panelwidth; params.gravity = gravity.left; slidinglayout.clearanimation(); slidinglayout.setlayoutparams(params); slidinglayout.requestlayout(); } @override public void onanimationrepeat(animation animation) { // todo auto-generated method stub } @override public void onanimationstart(animation animation) { // todo auto-generated method stub } } ///here xml <framelayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <!-- menu panel --> <relativelayout android:id="@+id/menupanel" android:layout_width="wrap_content" android:layout_height="match_parent" android:background="@drawable/gray_bg" android:gravity="right" android:orientation="vertical" > <textview android:id="@+id/menu_title_1" android:layout_width="fill_parent" android:layout_height="50dp" android:layout_alignparenttop="true" android:layout_marginleft="0dp" android:background="#353535" android:gravity="center_vertical" android:paddingleft="15dp" android:text="@string/menu_title" android:textcolor="@android:color/white" > </textview> <view android:id="@+id/menu_item_divider_1" android:layout_width="fill_parent" android:layout_height="0.5dp" android:layout_below="@+id/menu_title_1" android:layout_marginleft="0dp" android:layout_marginright="0dp" android:background="#b5b5b5" /> <textview android:id="@+id/menu_item_1" android:layout_width="fill_parent" android:layout_height="50dp" android:layout_below="@+id/menu_item_divider_1" android:layout_marginleft="15dp" android:gravity="center_vertical" android:text="@string/korean" > </textview> <view android:id="@+id/menu_item_divider_2" android:layout_width="fill_parent" android:layout_height="0.5dp" android:layout_below="@+id/menu_item_1" android:layout_marginleft="5dp" android:layout_marginright="5dp" android:background="#b5b5b5" /> <textview android:id="@+id/menu_item_2" android:layout_width="fill_parent" android:layout_height="50dp" android:layout_below="@+id/menu_item_divider_2" android:layout_marginleft="15dp" android:gravity="center_vertical" android:text="@string/english" > </textview> <!-- sliding panel --> <linearlayout android:id="@+id/slidingpanel" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@android:color/white" android:gravity="left" android:orientation="vertical" > <view android:id="@+id/dividerheaderbottom" android:layout_width="fill_parent" android:layout_height="1dp" android:background="#414141" /> <relativelayout android:id="@+id/header" android:layout_width="match_parent" android:layout_height="45dp" android:background="@color/whitec" > <button android:id="@+id/buttonback" android:layout_width="40dp" android:layout_height="40dp" android:layout_alignbottom="@+id/buttonperson" android:layout_alignparenttop="true" android:layout_marginright="14dp" android:layout_toleftof="@+id/buttonperson" android:background="@drawable/back" /> <imageview android:id="@+id/menuviewbutton" android:layout_width="40dp" android:layout_height="40dp" android:layout_centervertical="true" android:layout_marginleft="27dp" android:layout_torightof="@+id/buttonyummy" android:clickable="true" android:contentdescription="@string/description" android:src="@drawable/lin" android:visibility="visible" /> </relativelayout> </linearlayout> </framelayout>
Comments
Post a Comment