0

嗨我正在設計一個導航應用程序作爲一個Uni項目。我遇到了讓按鈕在軟鍵盤下方停留的問題。我使用LinearLayout作爲框架。我搜索了很多,並嘗試不同的技術,但似乎沒有任何工作。LinearLayout中的Softkeyboard移動按鈕

a picture of the problem

這裏是我的XML文件:

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

    <LinearLayout 
     android:layout_width="0px" 
     android:layout_height="0px" 
     android:focusable="true" 
     android:focusableInTouchMode="true" /> 

    <requestFocus /> 

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

     <EditText 
      android:id="@+id/navi_searchfield1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" 
      android:hint="Current location" > 
     </EditText> 

     <ListView 
      android:id="@+id/navi_listview1" 
      android:layout_width="fill_parent" 
      android:layout_height="0dp"> 
     </ListView> 

     <EditText 
      android:id="@+id/navi_searchfield2" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" 
      android:hint="Destination" /> 

     <ListView 
      android:id="@+id/navi_listview2" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" > 
     </ListView> 

    </LinearLayout> 

    <Button 
     android:id="@+id/start_navigation" 
     android:layout_width="fill_parent" 
     android:layout_height="40dip" 
     android:background="@drawable/start" 
     android:textColor="#ffffff" 
     android:text="Start navigation" /> 

</LinearLayout> 

回答

1

在AndroidManifest.xml中添加android:windowSoftInputMode="adjustPan"到您的活動爲:

<activity 
       android:windowSoftInputMode="adjustPan" 
. 
. 
.     
    </activity> 

這將防止SoftKeyboard移動你的按鈕,給你一個輸出: enter image description here

即使通過在屏幕上滾動顯示鍵盤,也可以使用該按鈕。但我認爲你可能無法顯示鍵盤按鈕上方,因爲我與SoftKeyboard工作,它使用:

android:layout_alignParentBottom="true" 

所以,你只能讓您的佈局由SoftKeyboard被推安全。

+0

添加android:windowSoftInputMode =「adjustPan」沒有工作既沒有android:layout_alignParentBottom =「true」或兩者在一起... – Philip

+0

@PhilipMasek我說[Softkeyboard](http://pastebin.com/trhPZG1U)使用** android:layout_alignParentBottom =「true」**這就是爲什麼它始終從底部彈出,不能使用沒有** RelativeLayout **的android:layout_alignParentBottom。 ** android:windowSoftInputMode =「adjustPan」**對我來說是完美的,我試着用你的XML。您可以嘗試使用以下** XML **和** Manifest File **,這對我很有用。 [XML](http://pastebin.com/inepx8JK) [清單(http://pastebin.com/HwZC5caP) –

+0

複製所有代碼到項目可惜仍然沒有成功... – Philip