0

我的布局如下,我希望 Img_1 在 vi​​ewpager 前面。现在我的布局是 Img_1 在 vi​​ewpager 的后面,而 Img_2 在 vi​​ewpager 的前面。

  <?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)
4

2 回答 2

0

尝试这个...

  <?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>
于 2013-11-11T08:05:43.557 回答
0

需要在“ViewPager”顶部带来前景左侧“不喜欢”图片,请参见下面的屏幕截图和 XML 代码。

<TextView
    android:id="@+id/Text"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="15dp"
    android:gravity="center_horizontal"
    android:shadowDx="1"
    android:shadowDy="1"
    android:shadowRadius="3"
    android:text="Like or Dislike?"
    android:textColor="#FF2400"
    android:textSize="35sp"
    android:textStyle="bold"
    android:typeface="serif" />

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp" >

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal" >

    <ImageView
        android:id="@+id/dislike"
        android:layout_width="85dp"
        android:layout_height="85dp"
        android:layout_gravity="center_vertical"
        android:layout_marginRight="-50dp"
        android:src="@drawable/image_dislike_shape"
        android:adjustViewBounds="true"
        android:scaleType="fitXY" />

    <android.support.v4.view.ViewPager
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/view_pager"
        android:layout_width="300dp"
        android:layout_height="220dp"
        android:layout_gravity="center_vertical|center_horizontal"
        android:layout_marginTop="5dp"
        android:background="@color/light_green" />
        <!-- android:layout_weight="1" -->

    <ImageView
        android:id="@+id/like"
        android:layout_width="85dp"
        android:layout_height="85dp"
        android:layout_gravity="center_vertical"
        android:layout_marginLeft="-50dp"
        android:src="@drawable/image_like_shape" />

    </TableRow>
</TableLayout>

[![Beer Liker App][2]][3]

于 2015-07-23T13:50:03.650 回答