2013-02-10 88 views
0

在我的布局中,我在布局中显示一个admob广告,内容为EditText。当我专注在编辑文本输入的东西出现的键盘,并通过EditText上移动的AdMob广告,你不能看到你所键入的内容。布局在键盘显示时得到调整

这是我的布局

<?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:layout_width="match_parent" 
android:layout_height="match_parent" 
android:isScrollContainer="false" > 

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/wood_floor" > 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <com.tyczj.bowling.adapters.RobotoThinTextView 
      android:id="@+id/textView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="40dp" 
      android:layout_marginTop="30dp" 
      android:text="Add Bowler" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:textColor="#33b5e5" 
      android:textSize="40dp" /> 

     <FrameLayout 
      android:id="@+id/line" 
      android:layout_width="fill_parent" 
      android:layout_height="2dp" 
      android:layout_alignParentLeft="true" 
      android:layout_below="@+id/textView2" 
      android:layout_marginLeft="20dp" 
      android:layout_marginRight="20dp" 
      android:layout_marginTop="8dp" 
      android:background="@drawable/ab_solid_custom_blue_inverse_holo" > 
     </FrameLayout> 

     <com.tyczj.bowling.adapters.RobotoThinTextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignLeft="@+id/line" 
      android:layout_below="@+id/line" 
      android:layout_marginTop="20dp" 
      android:text="@string/bNameTV" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <EditText 
      android:id="@+id/editText1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignBottom="@+id/textView1" 
      android:layout_below="@+id/line" 
      android:layout_marginLeft="30dp" 
      android:layout_marginRight="20dp" 
      android:layout_toRightOf="@+id/textView1" 
      android:inputType="textCapSentences" > 

      <requestFocus /> 
     </EditText> 

     <EditText 
      android:id="@+id/editText2" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignBottom="@+id/textView3" 
      android:layout_below="@+id/editText1" 
      android:layout_marginLeft="30dp" 
      android:layout_marginRight="20dp" 
      android:layout_toRightOf="@+id/textView3" 
      android:inputType="textCapSentences" > 

      <requestFocus /> 
     </EditText> 

     <com.tyczj.bowling.adapters.RobotoThinTextView 
      android:id="@+id/textView3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignLeft="@+id/line" 
      android:layout_below="@+id/textView1" 
      android:layout_marginTop="20dp" 
      android:text="@string/lNameTV" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <RadioButton 
      android:id="@+id/radioButton1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignLeft="@+id/textView3" 
      android:layout_below="@+id/textView3" 
      android:layout_marginTop="15dp" 
      android:checked="true" 
      android:text="Right Handed" /> 

     <RadioButton 
      android:id="@+id/radioButton2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignLeft="@+id/line" 
      android:layout_below="@+id/radioButton1" 
      android:text="Left Handed" /> 

     <Button 
      android:id="@+id/done" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignLeft="@+id/line" 
      android:layout_alignParentBottom="true" 
      android:layout_below="@+id/radioButton2" 
      android:onClick="onDoneClick" 
      android:text="@string/done" /> 
    </RelativeLayout> 
</ScrollView> 

<com.google.ads.AdView 
    android:id="@+id/ad" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    ads:adSize="IAB_BANNER" 
    ads:loadAdOnCreate="true" /> 

</RelativeLayout> 

在我的清单我在活动中设置了android:windowSoftInputMode="stateVisible|adjustResize"但该功能没有任何效果

如何在键盘出现时阻止广告移动?

回答

0

你试过了adjustPan模式吗?这可能对你更好。由于您有一个RelativeLayout,其元素与屏幕底部对齐,因此adjustResize将始终将该元素保留在屏幕底部。您可以使用您的布局来修改内容,方法是将广告放在滚动视图的下方,而不是调整到底部。

+0

如果我补充一点,该广告不动,但滚动视图不滚动,它会需要键盘出现时,否则你不能得到任何其他布局元素 – tyczj 2013-02-10 17:29:07

0

尝试使用LinearLayout,而不是最外层RelativeLayout并添加ScrollViewandroid:layout_weight="1"AdViewandroid:layout_weight="0"

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"> 

    <ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="0" 
    android:layout_weight="1" 
    ... 
    /> 
    ... 
    </ScrollView> 

    <com.google.ads.AdView 
    android:layout_width="fill_parent" 
    android:layout_height="0" 
    android:layout_weight="0" 
    .../> 

</LinearLayout>