我的布局如下,我希望 Img_1 在 viewpager 前面。现在我的布局是 Img_1 在 viewpager 的后面,而 Img_2 在 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>
以下是我尝试运行代码时的错误:-
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)