RelativeLayout问题。键盘显示时,ImageView向上滚动

时间:2011-09-28 21:54:27

标签: android android-layout relativelayout adview

我正在尝试在AdView下显示ImageView,如图片2。问题在于EditText处于活动状态,显示键盘,如果加载了AdView,所有工作都很完美,但是当未加载AdView时,ImageView会向上滚出屏幕,如图像1

这是我的xml布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gravity="top">

<com.google.ads.AdView android:layout_width="wrap_content"
    android:id="@+id/adView" android:layout_height="wrap_content"
    ads:adUnitId="XXXXXXXXX" ads:adSize="BANNER" ads:loadAdOnCreate="true"
    android:layout_alignParentTop="true" android:layout_centerHorizontal="true" />

<ImageView android:src="@drawable/frame008" android:id="@+id/imageView1"
    android:scaleType="centerInside" android:layout_height="wrap_content"
    android:adjustViewBounds="true" android:focusable="false"
    android:layout_width="match_parent" android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true" android:layout_marginTop="50dip"></ImageView>

EditText和Submit按钮:

<RelativeLayout android:id="@+id/linearLayout4"
    android:orientation="horizontal" android:layout_height="wrap_content"
    android:layout_width="fill_parent" android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true">
    <Button android:text="Submit" android:id="@+id/button2"
        android:onClick="submit" android:layout_height="wrap_content"
        android:layout_width="wrap_content" android:layout_alignParentRight="true"></Button>
    <EditText android:layout_width="wrap_content" android:id="@+id/editText1"
        android:layout_height="wrap_content" android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@id/button2">
        <requestFocus></requestFocus>
    </EditText>

</RelativeLayout>

感谢您的时间!!

When ads doesn't load.

When ads loads

1 个答案:

答案 0 :(得分:0)

下面的代码段应该是您根据需要定位视图所需的代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout >

    <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_alignParentTop="true" />

    <RelativeLayout 
        android:id="@+id/linearLayout4"
        android:layout_alignParentBottom="true">
    </RelativeLayout>

    <ImageView 
        android:layout_below="@+id/adView"
        android:layout_above="@+id/linearLayout4">
    </ImageView>

</RelativeLayout>