imageview bring to front from viewpager

My Layout as below and i wants the Img_1 in front of viewpager. Now my layout is Img_1 at the back of viewpager and Img_2 is in front of viewpager.

  <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/black"
        android:orientation="vertical" >

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

         <ImageButton 
            android:id="@+id/Img_1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentTop="true"
      android:layout_alignParentRight="true"
      android:background="@color/black"
      android:layout_margin="10dp"
      android:src="@drawable/Images1"/>



        <ImageButton 
            android:id="@+id/Img_2"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_alignParentRight="true"
      android:background="@color/black"
      android:layout_margin="10dp"
      android:src="@drawable/Images2"/>

    </RelativeLayout>

Below is my error when try to run the code :-

 11-11 17:07:28.665: E/AndroidRuntime(3961): FATAL EXCEPTION: main
    11-11 17:07:28.665: E/AndroidRuntime(3961): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.Viewpager}: java.lang.ClassCastException: android.support.v4.view.ViewPager cannot be cast to android.widget.ImageButton
    11-11 17:07:28.665: E/AndroidRuntime(3961):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
    11-11 17:07:28.665: E/AndroidRuntime(3961):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
    11-11 17:07:28.665: E/AndroidRuntime(3961):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
    11-11 17:07:28.665: E/AndroidRuntime(3961):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
    11-11 17:07:28.665: E/AndroidRuntime(3961):     at android.os.Handler.dispatchMessage(Handler.java:99)
    11-11 17:07:28.665: E/AndroidRuntime(3961):     at android.os.Looper.loop(Looper.java:137)
    11-11 17:07:28.665: E/AndroidRuntime(3961):     at android.app.ActivityThread.main(ActivityThread.java:5041)
    11-11 17:07:28.665: E/AndroidRuntime(3961):     at java.lang.reflect.Method.invokeNative(Native Method)
    11-11 17:07:28.665: E/AndroidRuntime(3961):     at java.lang.reflect.Method.invoke(Method.java:511)
    11-11 17:07:28.665: E/AndroidRuntime(3961):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    11-11 17:07:28.665: E/AndroidRuntime(3961):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    11-11 17:07:28.665: E/AndroidRuntime(3961):     at dalvik.system.NativeStart.main(Native Method)
    11-11 17:07:28.665: E/AndroidRuntime(3961): Caused by: java.lang.ClassCastException: android.support.v4.view.ViewPager cannot be cast to android.widget.ImageButton
    11-11 17:07:28.665: E/AndroidRuntime(3961):     at com.test.Viewpager.onCreate(Viewpager.java:109)
    11-11 17:07:28.665: E/AndroidRuntime(3961):     at android.app.Activity.performCreate(Activity.java:5104)
    11-11 17:07:28.665: E/AndroidRuntime(3961):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
    11-11 17:07:28.665: E/AndroidRuntime(3961):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)

Thanks in advanced.

Answer

Try this…

  <?xml version="1.0" encoding="utf-8"?>
            <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:background="@color/black"
                android:orientation="vertical" >

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

                     <ImageButton 
                    android:id="@+id/Img_1"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignParentTop="true"
              android:layout_alignParentRight="true"
              android:background="@color/black"
              android:layout_margin="10dp"
              android:src="@drawable/Images1"/>


      <ImageButton 
                    android:id="@+id/Img_2"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignParentBottom="true"
              android:layout_alignParentRight="true"
              android:background="@color/black"
              android:layout_margin="10dp"
              android:src="@drawable/Images2"/>

            </RelativeLayout>

Leave a Reply

Your email address will not be published. Required fields are marked *