Still my layout not shifting up side.

北城余情 提交于 2019-12-13 09:39:50

问题


I am trying to shift my layout up when soft keyboard will open.

I have edittext and button. I can see edittext clearly whether keyboard is open or not but problem is that i am showing drop down for edittext. When drop down open it open on top of edittext because there is no sufficient space between keyboard and dropdown.

So i am trying to shift my entire screen up (only edittext will show). So can show dropdown below of Edittext.

I try following things...

  1. I add following attribute in my activity in AndroidManifest.xml

    android:windowSoftInputMode="adjustPan"

  2. I add following code in my .java file

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)

I read somewhere i need to use relative layout. I also try this but none of them helpful.

Here is my xml code for your reference.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="#EFEFEF"
 >

<ViewStub
    android:id="@+id/vsHeader2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:inflatedId="@+id/header"
    android:layout="@layout/copyofheader" />



        <TextView
            android:id="@+id/firstPara"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="56dip"
            android:paddingLeft="12dp"
            android:paddingRight="12dp"
            android:text=""
            android:textSize="16sp" />

        <TextView
            android:id="@+id/secondPara"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/firstPara"
            android:layout_marginTop="24dip"
            android:paddingLeft="12dp"
            android:paddingRight="12dp"
            android:text=""
            android:textColor="#666666"
            android:textSize="16sp" />

         <AutoCompleteTextView
            android:id="@+id/mysecondautocomplete"
            android:layout_width="fill_parent"
            android:layout_height="40dip"
            android:layout_below="@id/secondPara"
            android:layout_marginLeft="12dip"
            android:layout_marginRight="12dip"
            android:layout_marginTop="12dip"                
             android:ems="10"

             android:dropDownVerticalOffset="44dip"
             android:windowSoftInputMode="stateHidden"
             android:dropDownHeight="290dip"    
              android:imeOptions="actionSearch"
            android:drawableLeft="@drawable/search_grey"
            android:background="@drawable/borderforloginedittext"
            android:drawablePadding="6dip"
            android:hint="Enter Restaurant Name"
            android:inputType="textPersonName"
             android:dropDownWidth="match_parent"
            android:textColor="#cc3333"
            android:textColorHint="#999999"
            android:textSize="16sp" />

I don't understand why my layout not shifting up. Please give me any hint or reference.


回答1:


UPDATE:

I just re-read your question and found the mistake you are making. You are adding android:windowSoftInputMode="adjustPan" in AndroidManifestfor resizing or scaling the window for the keyboard.

You should use android:windowSoftInputMode="adjustResize" which will resize the window or adjust the window accordingly.


Try this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
>

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

<RelativeLayout
  android:layout_width="match_parent"
  android:layout_height="fill_parent"
  android:background="#EFEFEF"
 >

<ViewStub
android:id="@+id/vsHeader2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inflatedId="@+id/header"
android:layout="@layout/copyofheader" />



    <TextView
        android:id="@+id/firstPara"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="56dip"
        android:paddingLeft="12dp"
        android:paddingRight="12dp"
        android:text=""
        android:textSize="16sp" />

    <TextView
        android:id="@+id/secondPara"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/firstPara"
        android:layout_marginTop="24dip"
        android:paddingLeft="12dp"
        android:paddingRight="12dp"
        android:text=""
        android:textColor="#666666"
        android:textSize="16sp" />

     <AutoCompleteTextView
        android:id="@+id/mysecondautocomplete"
        android:layout_width="fill_parent"
        android:layout_height="40dip"
        android:layout_below="@id/secondPara"
        android:layout_marginLeft="12dip"
        android:layout_marginRight="12dip"
        android:layout_marginTop="12dip"                
         android:ems="10"

         android:dropDownVerticalOffset="44dip"
         android:windowSoftInputMode="stateHidden"
         android:dropDownHeight="290dip"    
          android:imeOptions="actionSearch"
        android:drawableLeft="@drawable/search_grey"
        android:background="@drawable/borderforloginedittext"
        android:drawablePadding="6dip"
        android:hint="Enter Restaurant Name"
        android:inputType="textPersonName"
         android:dropDownWidth="match_parent"
        android:textColor="#cc3333"
        android:textColorHint="#999999"
        android:textSize="16sp" />
    </RelativeLayout>
  </ScrollView>
</RelativeLayout>



回答2:


Put your entire layout inside a Scrollview. So when the soft keyboard gets open, your view will get adjusted accordingly.



来源:https://stackoverflow.com/questions/18634323/still-my-layout-not-shifting-up-side

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!