View Pager - how can I put fixed buttons on top of it?

In my Android app, I have a pager with a view, which is a slide show of images. these images are background images of 5 different fragments.

I want to put two buttons on top of everything, and these buttons remain fixed on the screen. How can i do this?

public class WhatIsThis extends SherlockFragmentActivity {

    private static final int NUM_PAGES = 5;
    private ViewPager mPager;
    private PagerAdapter mPagerAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.welcome_slides_view_pager);

        // Instantiate a ViewPager and a PagerAdapter.
        mPager = (ViewPager) findViewById(R.id.pager);
        mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
        mPager.setAdapter(mPagerAdapter);
    }

    @Override
    public void onBackPressed() {
        if (mPager.getCurrentItem() == 0) {
            super.onBackPressed();
        } else {

            mPager.setCurrentItem(mPager.getCurrentItem() - 1);
        }
    }


    private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
        public ScreenSlidePagerAdapter(FragmentManager fragmentManager) {
            super(fragmentManager);
        }


        @Override
        public SherlockFragment getItem(int position) {
            if(position == 1) {
                return new WelcomeSlideFragmentA();
            } else if (position == 2) {
                return new WelcomeSlideFragmentB();
            } else if (position == 3) {
                return new WelcomeSlideFragmentC();
            } else if (position == 4) {
                return new WelcomeSlideFragmentD();
            } else {
                return new WelcomeSlideFragmentE();
            }
        }

        @Override
        public int getCount() {
            return NUM_PAGES;
        }
    }

}

welcome_slides_view_pager.xml:

<android.support.v4.view.ViewPager
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
+4
source share
4 answers

You can simply replace the contents of the greeting_slides_view_pager.xml as follows:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <Button
        android:id="@+id/button_previous"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="10dp"
        android:text="Previous" />

    <Button
        android:id="@+id/button_next"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="10dp"
        android:text="Next" />
</RelativeLayout>

viewpager ( , , , , ).

+13

+1

2 .

1 .

2 , Activity NAVIGATION_MODE_TABS ActionBar.

, .

0

:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical" >
       <LinearLayout 
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:orientation="horizontal" >
          <Button
             android:id="@+id/button1"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="Button1" />
          <Button
             android:id="@+id/button2"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="Button2" />Ï
       </LinearLayout>
       <android.support.v4.view.ViewPager
             android:id="@+id/pager"
         android:layout_width="match_parent"
         android:layout_height="match_parent" />
</LinearLayout>
-1

All Articles