Android實現仿qq側邊欄效果
阿新 • • 發佈:2019-02-12
public class MenuActivity extends FragmentActivity implements View.OnClickListener{ private ResideMenu resideMenu; private MenuActivity mContext; private ResideMenuItem itemHome; private ResideMenuItem itemProfile; private ResideMenuItem itemCalendar; private ResideMenuItem itemSettings; /** * Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mContext = this; setUpMenu(); if( savedInstanceState == null ) changeFragment(new HomeFragment()); } private void setUpMenu() { // attach to current activity; resideMenu = new ResideMenu(this); resideMenu.setBackground(R.drawable.menu_background); resideMenu.attachToActivity(this); resideMenu.setMenuListener(menuListener); //valid scale factor is between 0.0f and 1.0f. leftmenu'width is 150dip. resideMenu.setScaleValue(0.6f); // create menu items; itemHome = new ResideMenuItem(this, R.drawable.icon_home, "Home"); itemProfile = new ResideMenuItem(this, R.drawable.icon_profile, "Profile"); itemCalendar = new ResideMenuItem(this, R.drawable.icon_calendar, "Calendar"); itemSettings = new ResideMenuItem(this, R.drawable.icon_settings, "Settings"); itemHome.setOnClickListener(this); itemProfile.setOnClickListener(this); itemCalendar.setOnClickListener(this); itemSettings.setOnClickListener(this); resideMenu.addMenuItem(itemHome, ResideMenu.DIRECTION_LEFT); resideMenu.addMenuItem(itemProfile, ResideMenu.DIRECTION_LEFT); resideMenu.addMenuItem(itemCalendar, ResideMenu.DIRECTION_RIGHT); resideMenu.addMenuItem(itemSettings, ResideMenu.DIRECTION_RIGHT); // You can disable a direction by setting -> // resideMenu.setSwipeDirectionDisable(ResideMenu.DIRECTION_RIGHT); findViewById(R.id.title_bar_left_menu).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { resideMenu.openMenu(ResideMenu.DIRECTION_LEFT); } }); findViewById(R.id.title_bar_right_menu).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { resideMenu.openMenu(ResideMenu.DIRECTION_RIGHT); } }); }