I am developing an app in which i have to use left and right menu.I googled and found SlidingMenu library of #jfeinstein
Things are working fine i am able to open both left and right menu.But The only problem is that the secondry menu opens with unnecessary extra spacing.I need to remove that extra spacing.I have attached the screen shots also.
here spacing is fine
Please let me know the solution.
But here i need to make the content fit inside the menu.
and here is Activity for displaying menu
public class BaseSlidingMenuActivity extends SlidingFragmentActivity {
private int mTitleRes;
protected ListFragment mFrag;
protected SlideLeftMenuFragment mLeftFrag;
/**
* Title for Sliding Menu.
*
* #param titleRes
*/
public BaseSlidingMenuActivity(int titleRes) {
mTitleRes = titleRes;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(mTitleRes);
// set the Behind View
setBehindContentView(R.layout.menu_frame);
if (savedInstanceState == null) {
FragmentTransaction t = this.getSupportFragmentManager().beginTransaction();
mFrag = new SlideRightMenuFragment();
t.replace(R.id.menu_frame, mFrag);
t.commit();
} else {
mFrag = (ListFragment) this.getSupportFragmentManager().findFragmentById(R.id.menu_frame);
}
// customize the SlidingMenu
final SlidingMenu sm = getSlidingMenu();
sm.setMode(SlidingMenu.LEFT_RIGHT);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
sm.setShadowWidthRes(R.dimen.shadow_width);
sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
sm.setShadowDrawable(R.drawable.shadow);
sm.setFadeDegree(0.35f);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
sm.setSecondaryMenu(R.layout.menu_frame_two);
sm.setSecondaryShadowDrawable(R.drawable.shadowright);
mLeftFrag = new SlideLeftMenuFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.menu_frame_two, mLeftFrag).commit();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
// setSlidingActionBarEnabled(false);
}
Thanks in advance
I had forked a new branch to add this feature from jfeinstein's slidemenu.
https://github.com/buptcoder/SlidingMenu
in my branch, I added a new method for SlideMenu.
You can use
sm.setRightBehindOffset(200);
to adjust the right menu's width.
Any problems please let me know.
Related
First of all I am sorry to ask repeated questions. As this has been asked before but some how I could not understand properly.
I found a good solutions here. I followed and could add library to my project. Now I need to add left and right sliding menus to my project without action-bar. Here is the picture-
If I click any of the selected button then it should open the respective sliding page(once at a time) at the specific sides. Something like -
currently -
I am able to generate one side of the menu bar. It is working with sliding only. -
public class MainActivity extends FragmentActivity {
ViewPager viewPager;
PagerAdapter adapter;
CirclePageIndicator mIndicator;
private int mWidthScreen;
private int mHeightScreen;
private Bundle bundle;
private List<Fragment> frgScreens;
private int selectedtheme;
private Handler mHandler = new Handler();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the view from viewpager_main.xml
setContentView(R.layout.viewpager_main);
SlidingMenu menu;
menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setShadowWidth(5);
menu.setFadeDegree(0.0f);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
menu.setBehindWidth(500);
menu.setMenu(R.layout.menu_frame);
}
Now I want in both sides and should open menu by clicking the button
Any help will be appreciated. Please feel free to ask any queries.
Well Finally I did it. Here mBtnMenu is an ImageView.
mBtnMenu = (ImageView) findViewById(R.id.btnMenu);
menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setShadowWidth(5);
menu.setFadeDegree(0.0f);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
menu.setBehindWidth(500);
menu.setMenu(R.layout.menu_frame);
mBtnMenu.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// menu.showMenu();
menu.toggle();
}
});
I am using J.Feinstein library of sliding menu and it works great... The only problem i have is that it closes only if i touch outside the sliding menu or if i swipe from right to left from outside the sliding menu..
But what actually i want is that it will also swipe from right to left to close when i swipe it by finger on it, not only from outside of it...
I searched a lot.. In fact i read the source code of library and found the function getSlidingMenu(true); but that does not fulfill my requirement .. I am new to android... Kindly help me out and tell me how to do this..
Here is my piece of code..
public class ViewPagerActivity extends SlidingFragmentActivity{
// Tab titles
private String[] tabs = { "First", "Second", "Third" };
public ViewPagerActivity() {
super();
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(R.string.viewpager);
setContentView(R.layout.pager);
// customize the SlidingMenu
final SlidingMenu sm = getSlidingMenu();
sm.setShadowWidthRes(R.dimen.shadow_width);
sm.setShadowDrawable(R.drawable.shadow);
sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
sm.setFadeDegree(0.35f);
sm.setScrollBarStyle(2);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
//sm.setSlidingEnabled(true);
//sm.setTouchmodeMarginThreshold(2);
getSlidingMenu().setSlidingEnabled(true);
setBehindContentView(R.layout.menu_frame);
}
}
If you want this type of sliding then use view pager with sliding....
http://javapapers.com/android/android-image-slider-tutorial/
this will surely help you and you will no have to face this kind of problem...
I am Completely new to android and i've been given a task of having sliding menus on click of a buttons placed on either side of the corners. Very similar to that of Facebook app. I tried using the SherlockAction bar library and the Slidingmenu library but I don't quite understand its functioning. Please help me out.
Thanks in advance
If you need to use ABS with SlidingMenu first of all go into the SlidingActivities that you plan on using make them extend Sherlock__Activity instead of __Activity.
Then simply try:
public class FragmentsHolderActivity extends SlidingFragmentActivity {
public static boolean isChangeCategoryAllow = true;
public static ImageLoader imageLoader = ImageLoader.getInstance();
public MenuItem mRefreshMenuItem;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
final SlidingMenu sm = getSlidingMenu();
sm.setFadeEnabled(false);
sm.setShadowWidthRes(R.dimen.shadow_width);
sm.setShadowDrawable(R.drawable.shadow);
sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
// set the Above View
setContentView(R.layout.content_frame);
//add if you need dinamically customize your fragment as your liking.
/*getSupportFragmentManager()
.beginTransaction()
.replace(R.id.content_frame, new CategoryImagesListFragment())
.commit();*/
// set the Behind View
setBehindContentView(R.layout.menu_frame);
//add if you need dinamically customize the SlidingMenu as your liking.
/*getSupportFragmentManager()
.beginTransaction()
.replace(R.id.menu_frame, new CategoryFragment())
.commit(); */
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case android.R.id.home:
toggle();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
setBehindContentView will place the view in the "behind" portion of the SlidingMenu.
I have my MainActivity like
public class MainActivity extends SlidingFragmentActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// Main layout
setContentView(R.layout.activity_main);
setBehindContentView(R.layout.menu_frame);
// SlidingMenu
sm = getSlidingMenu();
sm.setFadeDegree(0.35f);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
sm.setBehindOffset(120);
sm.setMode(SlidingMenu.LEFT_RIGHT);
// Left menu
getSupportFragmentManager().beginTransaction()
.replace(R.id.menu_frame, new LeftMenuFragment()).commit();
// Right menu
getSlidingMenu().setSecondaryMenu(R.layout.menu_frame_second);
getSupportFragmentManager().beginTransaction()
.replace(R.id.menu_frame_two, new RightMenuFragment()).commit();
}
}
How can I create vertical pager in this activity? I want to also to scroll vertical between two layouts(fragments).
you can use this library, but it doesn't seems it is supported anymore
I want to remove from the arrow image from the HomeAsUpButton.
I tried removing the arrow's ImageView from the layout (nothing happens) and also tried using SupportActionBar.SetDisplayHomeAsUpEnabled(false); removes the button functionality entirely.
I'm using johnkil's SideNavigation code. Any suggestions?
Using YouTube's App as example:
With the ActionBar Sherlock, inside your Activity's onCreate method, you just need to do the following:
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
If the up image does not disappear, it might be something related to the library that you referred. In my app, I use the SlidingMenu library and it works just fine (source: https://github.com/jfeinstein10/SlidingMenu)
EDIT: With the SlidingMenu library, the Activity would look like this:
public class MainAct extends SlidingFragmentActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Sliding menu
// Here I set the menu's layout
setBehindContentView(R.layout.menu_frame);
FragmentTransaction t = getSupportFragmentManager().beginTransaction();
MenuListFrag frag = MenuListFrag.newInstance(getSlidingMenuItems());
t.replace(R.id.menu_frame, frag);
t.commit();
// Customizing the SlidingMenu
SlidingMenu sm = getSlidingMenu();
sm.setShadowWidthRes(R.dimen.shadow_width);
sm.setShadowDrawable(R.drawable.shadow);
sm.setFadeDegree(0.35f);
// Hiding the ActionBar's up button
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setHomeButtonEnabled(true);
}
}
You can disable the action bar using this method
actionBar.setHomeButtonEnabled(false);
I was able to hide the "arrow" by setting a transparent image.