Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
339 views
in Technique[技术] by (71.8m points)

background layout moving when soft keyboard displayed - android

I've got an input popup that I'm displaying over my activities main view that has some edit boxes in it. When the popup is displayed the activities view stays dimmed in the background (like with an alert dialog).

The issue I'm having is that when the keyboard comes up the popup is ok, but activities view in the background is shifting up. That view should be paused and I wouldn't have thought it would be affected by the keyboard at all. Is there any way to stop this from happening?

I've tried adding android:windowSoftInputMode="adjustPan" to the activity and to the pop-up with no luck.

Here's my activity layout:

<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:orientation="vertical" android:background="@drawable/main_bg">

<include android:id="@+id/header" layout="@layout/common_header" android:layout_width="fill_parent" android:layout_height="wrap_content"/>

 <RelativeLayout
  android:id="@+id/contentLayout"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:layout_margin="5dp"
 >

<include android:id="@+id/btnBar" layout="@layout/common_button_bar" 
android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:layout_alignParentBottom="true"/>  

  <LinearLayout
   android:id="@+id/webLayout"
   android:layout_above="@+id/btnBar"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:background="@drawable/blk"
  android:layout_margin="10dp">

   <WebView
android:id="@+id/WebView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="1dp"
android:background="@drawable/white"
   >


   </WebView>

  </LinearLayout>
 </RelativeLayout>
    </LinearLayout>

and here is my pop-up layout:

<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_height="wrap_content"
 android:orientation="vertical"
 android:background="@color/light_grey" android:layout_width="wrap_content"      android:minWidth="300dp">
 <LinearLayout
  android:id="@+id/main_inner_layout"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical"
  android:background="@color/white"
  android:layout_margin="3dp"
 >

  <TextView
   android:id="@+id/enter_txt"
   android:text="Enter Cup Code Below:"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:gravity="center_horizontal"
   android:textColor="@color/black"
   android:layout_gravity="left"
   android:typeface="sans"
   android:textSize="16dp"
   android:layout_margin="10dp"
      >
  </TextView>
  <RelativeLayout
    android:id="@+id/code_layout"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:layout_marginLeft="10dp"
   android:layout_marginRight="10dp"
   android:background="@color/white"
  >
   <EditText
    android:text="12345"
    android:id="@+id/CodeInputOne"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginRight="10dp"
    android:layout_alignParentLeft="true"
   ></EditText>
   <EditText
    android:text="12345"
    android:id="@+id/CodeInputTwo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_centerHorizontal="true"
   ></EditText>
   <EditText
    android:text="12345"
    android:id="@+id/CodeInputThree"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_alignParentRight="true"
       ></EditText>
  </RelativeLayout>
  <RelativeLayout
   android:id="@+id/btn_layout_top"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:layout_marginLeft="10dp"
   android:layout_marginTop="10dp"
   android:layout_marginRight="10dp"
   android:background="@color/white"
  >
   <Button
    android:id="@+id/AccountBtn"
    android:textStyle="bold"
    android:text="My Account"
    android:layout_marginRight="5dp"
    android:layout_alignParentLeft="true"
    android:onClick="ClickHandler"
    android:layout_height="40dp"
    android:layout_width="130dp"
   ></Button>
   <Button
    android:id="@+id/SubmitBtn"
    android:textStyle="bold"
    android:text="Submit"
    android:layout_marginLeft="5dp"
    android:layout_alignParentRight="true"
    android:onClick="ClickHandler"
    android:layout_height="40dp"
    android:layout_width="130dp"
   ></Button>

  </RelativeLayout>
  <RelativeLayout
   android:id="@+id/btn_layout_bottom"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:layout_marginLeft="10dp"
   android:layout_marginRight="10dp"
   android:background="@color/white"
  >
   <Button
    android:id="@+id/RewardsBtn"
    android:textStyle="bold"
    android:text="Rewards"
    android:layout_marginRight="5dp"
    android:layout_alignParentLeft="true"
    android:onClick="ClickHandler"
    android:layout_height="40dp"
    android:layout_width="130dp"
       ></Button>
   <Button
    android:id="@+id/CancelBtn"
    android:textStyle="bold"
    android:text="Cancel"
    android:layout_marginLeft="5dp"
    android:layout_alignParentRight="true"
    android:onClick="ClickHandler"
    android:layout_height="40dp"
    android:layout_width="130dp"
   ></Button>
   </RelativeLayout>
 </LinearLayout>
</LinearLayout>

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try using

android:windowSoftInputMode="adjustPan|adjustResize"

for the activity.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...