1

I am working on ViewPager. I wrote code which can create ViewPager and also I have some java class, but I want my ViewPager must be below the layout. This is a my xml code

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

<RelativeLayout
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#171717" >

    <ImageButton
        android:id="@+id/menu_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginLeft="12dp"
        android:background="@drawable/ic_launcher" />

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="7.0mm"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:background="@drawable/ic_launcher" />

    <ToggleButton
        android:id="@+id/button_search"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="12dp"
        android:background="@drawable/ic_launcher"
        android:padding="2dip"
        android:textOff=""
        android:textOn="" />
</RelativeLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/relativeLayout1" >

    <android.support.v4.view.ViewPager
        android:id="@+id/vp_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/relativeLayout1" >
    </android.support.v4.view.ViewPager>
</RelativeLayout>

This is a my java code:

public class MainActivity extends FragmentActivity implements
    ActionBar.TabListener {

private ViewPager viewPager;
private TabsPagerAdapter mAdapter;
private ActionBar actionBar;
// Tab titles
private String[] tabs = { "test1", "test2", "test3", "test4",
        "test5" };

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    viewPager = (ViewPager) findViewById(R.id.vp_main);
    actionBar = getActionBar();

    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);
    mAdapter = new TabsPagerAdapter(getSupportFragmentManager());

    viewPager.setAdapter(mAdapter);
    actionBar.setHomeButtonEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Adding Tabs
    for (String tab_name : tabs) {
        actionBar.addTab(actionBar.newTab().setText(tab_name)
                .setTabListener(this));
    }

    /**
     * on swiping the viewpager make respective tab selected
     * */
    viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {

            actionBar.setSelectedNavigationItem(position);
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
        }
    });
}

@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}

@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    // on tab selected
    // show respected fragment view
    viewPager.setCurrentItem(tab.getPosition());
}

@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
}

}

result it like this

I want my viewpager(actionBar)should be rendered below the layout

A Paul
  • 8,113
  • 3
  • 31
  • 61
user3272799
  • 111
  • 1
  • 2
  • 6
  • if you want to render it below everything why you installed it after all other layouts ?! – Rudi Feb 05 '14 at 13:04
  • Could you post, how you get now ? – VIGNESH Feb 05 '14 at 13:05
  • i did not understand you.what do you mean. on my xml file i have two different RelativeLayout and and my ViewPager is un the second RelativeLayout and i want to second RelativeLayout should be first RelativeLayout's bellow but.when i run project first RelativeLayout is RelativeLayout's bellow (different result :( ) – user3272799 Feb 05 '14 at 13:08
  • this is a result http://postimg.org/image/glw7kko51/ – user3272799 Feb 05 '14 at 13:10
  • check my answer below and let me know what you got – Rudi Feb 05 '14 at 13:13

2 Answers2

0

Try this :

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

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true">

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

    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#171717" >

        <ImageButton
            android:id="@+id/menu_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="12dp"
            android:background="@drawable/ic_launcher" />

        <ImageView
            android:id="@+id/image"
            android:layout_width="wrap_content"
            android:layout_height="7.0mm"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:background="@drawable/ic_launcher" />

        <ToggleButton
            android:id="@+id/button_search"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="12dp"
            android:background="@drawable/ic_launcher"
            android:padding="2dip"
            android:textOff=""
            android:textOn="" />
    </RelativeLayout>

</RelativeLayout>

Also dont forget to clean your project . Hope it helps

Rudi
  • 4,304
  • 4
  • 34
  • 44
0

Check It Out, It will help u..

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

        <RelativeLayout
            android:id="@+id/relativeLayout1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#171717" >

            <ImageButton
                android:id="@+id/menu_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="12dp"
                android:background="@drawable/ic_launcher" />

            <ImageView
                android:id="@+id/image"
                android:layout_width="wrap_content"
                android:layout_height="7.0mm"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:background="@drawable/ic_launcher" />

            <ToggleButton
                android:id="@+id/button_search"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginRight="12dp"
                android:background="@drawable/ic_launcher"
                android:padding="2dip"
                android:textOff=""
                android:textOn="" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/relativeLayout1" >

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

    </RelativeLayout>
Namrata
  • 1,683
  • 1
  • 17
  • 28