Many products in Android (such as 360 Mobile Assistant, NetEase Menu...) adopt the side-sliding menu display form, which adopts this display form.
1. Save more presentation content in the menu
2. It can also reflect visual effects in design
This interaction method is becoming more and more popular now. Although this interaction method can be implemented through custom components, it is easier to use a three-party open source library.
SlidingMenu:SlidingMenu is a relatively new setting interface or configuration interface effect. Sliding left or right on the main interface shows the setting interface, which can facilitate various operations. Currently, a large number of applications are using this effect.
address:/jfeinstein10/
Now create a new Android project SlidingMenuDemo,
activity_main:
<RelativeLayout xmlns:andro xmlns:tools="/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="content" android:textSize="24sp" android:textColor="#000" android:gravity="center" /> </RelativeLayout>
The menu activity_menu on the left:
<LinearLayout xmlns:andro android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="40dp" android:gravity="center" android:text="physical education" android:textSize="16sp" android:textColor="#000" /> <TextView android:layout_width="fill_parent" android:layout_height="40dp" android:gravity="center" android:text="entertainment" android:textSize="16sp" android:textColor="#000" /> <TextView android:layout_width="fill_parent" android:layout_height="40dp" android:gravity="center" android:text="Financial" android:textSize="16sp" android:textColor="#000" /> <TextView android:layout_width="fill_parent" android:layout_height="40dp" android:gravity="center" android:text="science and technology" android:textSize="16sp" android:textColor="#000" /> <TextView android:layout_width="fill_parent" android:layout_height="40dp" android:gravity="center" android:text="Hangzhou" android:textSize="16sp" android:textColor="#000" /> </LinearLayout>
:
package ; import ; import ; import ; import ; import ; public class MainActivity extends SlidingFragmentActivity { private SlidingMenu sm; @Override public void onCreate(Bundle savedInstanceState) { (savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); // 1 Set the page next to the sliding menusetBehindContentView(.activity_menu); setContentView(.activity_main); //2 Get the sliding menusm = getSlidingMenu(); //3 Set the left scroll menu (); // 4 Set the remaining width of the content page after the sliding menu comes out(.slidingmenu_offset); (SlidingMenu.TOUCHMODE_FULLSCREEN); // 6 Set shadows(); (.shadow_width); } }
Note that Activity must inherit SlidingFragmentActivity.
Now take a look at some properties of SlidingMenu:
();//Set left scroll menu(SlidingMenu.TOUCHMODE_FULLSCREEN);//Set the sliding screen range, which can be swiped in the full screen area.();//Set shadow pictures(.shadow_width);//Set the width of the shadow picture(.slidingmenu_offset);//The remaining width displayed on the main page when SlidingMenu is marked(400);//Set the width of the SlidingMenu menu(0.35f);//The degree of gradient when SlidingMenu slides(this, SlidingMenu.SLIDING_CONTENT);// Make SlidingMenu attached to Activity(.menu_layout);//Set menu layout file();//Dynamic judgment automatically turns off or turns on SlidingMenu();//Show SlidingMenu();//Show content
You can mark the SlidingMenu menu at both sides and left and right. You only need to set it
(SlidingMenu.LEFT_RIGHT);property,Then set the layout file of the menu on the right ();//Shadow picture of the menu on the right
Set SlidingMenu property
sm = getSlidingMenu(); //If you only display the menu on the left, use LEFT, and RIGHT on the right, support both left and right, LEFT_RIGHT_(SlidingMenu.LEFT_RIGHT);//Set the menu sliding mode, whether the menu appears on the left or right, or both left and right sides.();//Set shadow image resources(.shadow_width);//Set the width of the shadow picture//(200);//Set the width of the menu(.slidingmenu_offset);//The remaining width displayed on the main page when SlidingMenu is marked(SlidingMenu.TOUCHMODE_FULLSCREEN);//Set the sliding area
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.