In android how to add Vertical ViewPager? - android

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

Related

Can't stop actionBar home icon from acting as a button

I need to stop the app icon in the upper left corner on the actionBar from acting as a button. I tried using actionBar.setHomeEnabled(false), but it isn't working and i'm not sure why. Any help is really appreciated. This is my onCreate method:
#SuppressLint("NewApi")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sound_board);
FragmentManager fm = getSupportFragmentManager();
Fragment fragment = fm.findFragmentById(R.id.fragmentContainer);
if(fragment == null){
fragment = new SoundBoardFragment();
fm.beginTransaction()
.add(R.id.fragmentContainer, fragment)
.commit();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
ActionBar actionBar = getActionBar();
actionBar.setHomeButtonEnabled(false);
}
}
You will also need to call setDisplayHomeAsUpEnabled(false)

Where I bind to XML when extends from ActionBarActivity?

when I extends from Activity, I modify the fragment_main and find controls like this:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);
MyButton = (Button) findViewById(R.id.button1);
}
but when I do this when extends from from ActionBarActivity gives me an error, so to do it work I have to comment:
/*if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}*/
and set activity_main to fragment_main
setContentView(R.layout.fragment_main);
but I don't believe this be correct...
You should not get the button view on your activity, however it sides in a fragment. You can get it on your fragment such as PlaceholderFragment like you do on your activity. If needed, you should know something about how to interactive between Activity and Fragment. the link http://developer.android.com/guide/components/fragments.html may help you.

Slidingmenu on both sides

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.

how to customize setSecondaryMenu's width of SlidingMenu library of jfeinstein

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.

How to remove HomeAsUpButton arrow from ActionBar Sherlock?

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.

Categories

Resources