How to use DrawerLayout side slip Control in Android
This article mainly explains "how to use the DrawerLayout side slip control in Android". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use DrawerLayout side slip control in Android".
Activity_sliding.xml:
Through the layout file above, we find that the sub-layout in drawerlayout is divided into three parts: content, left, and right. The layout of left and right needs to declare the android:layout_gravity attribute in layout, and the values are start and end, respectively. Obviously, the drawerlayout layout is similar to a large container, super-screen layout, placing the left layout at the beginning of the control and the right layout at the end of the control.
DrawerSlidingActivity.java:
Import android.graphics.Color;import android.os.Bundle;import android.support.v4.app.ActionBarDrawerToggle;import android.support.v4.widget.DrawerLayout;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.RelativeLayout;public class DrawwerSlidingActivity extends AppCompatActivity {/ / drawer menu object private ActionBarDrawerToggle drawerbar; public DrawerLayout drawerLayout; private RelativeLayout main_left_drawer_layout, main_right_drawer_layout; @ Override protected void onCreate (Bundle arg0) {super.onCreate (arg0) SetContentView (R.layout.activity_slidingmenu); initLayout (); initEvent ();} public void initLayout () {drawerLayout = (DrawerLayout) findViewById (R.id.main_drawer_layout); / / sets the background color drawerLayout.setScrimColor (Color.TRANSPARENT) for areas other than the menu content; / / left menu main_left_drawer_layout = (RelativeLayout) findViewById (R.id.main_left_drawer_layout) / / right menu main_right_drawer_layout = (RelativeLayout) findViewById (R.id.main_right_drawer_layout);} / set switch monitor private void initEvent () {drawerbar = new ActionBarDrawerToggle (this, drawerLayout, R.mipmap.ic_launcher, R.string.open, R.string.close) {/ / menu opens @ Override public void onDrawerOpened (View drawerView) {super.onDrawerOpened (drawerView) } / / menu close @ Override public void onDrawerClosed (View drawerView) {super.onDrawerClosed (drawerView);}}; drawerLayout.setDrawerListener (drawerbar);} / / left menu switch event public void openLeftLayout (View view) {if (drawerLayout.isDrawerOpen (main_left_drawer_layout)) {drawerLayout.closeDrawer (main_left_drawer_layout);} else {drawerLayout.openDrawer (main_left_drawer_layout) }} / / right menu switch event public void openRightLayout (View view) {if (drawerLayout.isDrawerOpen (main_right_drawer_layout)) {drawerLayout.closeDrawer (main_right_drawer_layout);} else {drawerLayout.openDrawer (main_right_drawer_layout) Thank you for reading, the above is the content of "how to use DrawerLayout side slip control in Android". After the study of this article, I believe you have a deeper understanding of how to use DrawerLayout side slip control in Android, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!