输入法显示时如何不覆盖EditText?

时间:2014-10-14 04:28:13

标签: android android-input-method

一个按钮和一个EditText以及我的PopupWindow中的其他内容 按钮位于PopupWindow的底部,但TextView不是。
当输入法显示时,我想按钮向上移动但不覆盖我的EditText 我怎么能这样做?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="@color/white">
<ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fillViewport="true"
            android:scrollbars="vertical"
            android:id="@+id/scroll_view">
     <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
         ...
         <EditText/> <!-- This is the EditText -->
         ...
     </LinearLayout>
</ScrollView>
<Button
        android:layout_width="match_parent"
        android:layout_height="@dimen/dimen_43_dip"
        android:layout_marginLeft="@dimen/dimen_17_dip"
        android:layout_marginRight="@dimen/dimen_17_dip"
        android:layout_marginTop="@dimen/dimen_11_dip"
        android:layout_marginBottom="@dimen/dimen_11_dip"
        android:layout_alignParentBottom="true"
        android:text="OK"
        style="@style/NormalButton"/>
</RelativeLayout>

enter image description here enter image description here
图2是我想要的。
有什么想法吗?

3 个答案:

答案 0 :(得分:2)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.dsa.MainActivity" >

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginTop="16dp"
        android:text="OK" />

    <ScrollView
        android:id="@+id/scroll_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/button1"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="62dp"
        android:fillViewport="true"
        android:scrollbars="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:hint="hjk" />
        </LinearLayout>
    </ScrollView>

</RelativeLayout>

请尝试这个希望它可以帮助你解决问题谢谢

答案 1 :(得分:0)

您需要在AndroidManifest.xml文件的activity标记中设置 android:windowSoftInputMode =&#34; adjustPan | stateAlwaysHidden&#34; 。就像下面一样

<activity
     android:name="com.src.personalhomemanager.MainActivity"
     android:label="@string/app_name"
     android:windowSoftInputMode="adjustPan|stateAlwaysHidden" >
</activity>
试试这个,可能会对你有帮助。

答案 2 :(得分:0)

试试这个,

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="@color/white">
<ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fillViewport="true"
            android:scrollbars="vertical"
            android:id="@+id/scroll_view"
            android:layout_above="@+id/ok_btn">
     <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
         ...
         <EditText/> <!-- This is the EditText -->
         ...
     </LinearLayout>
</ScrollView>
<Button
        android:id="@+id/ok_btn"
        android:layout_width="match_parent"
        android:layout_height="@dimen/dimen_43_dip"
        android:layout_marginLeft="@dimen/dimen_17_dip"
        android:layout_marginRight="@dimen/dimen_17_dip"
        android:layout_marginTop="@dimen/dimen_11_dip"
        android:layout_marginBottom="@dimen/dimen_11_dip"
        android:layout_alignParentBottom="true"
        android:text="OK"
        style="@style/NormalButton"/>
</RelativeLayout>