Android 軟鍵盤擋住輸入框的問題

當在Android的layout設計裏面若是輸入框過多,則在輸入彈出軟鍵盤的時候,下面的輸入框會有一部分被軟件盤擋住,從而不能獲取焦點輸入。android

下面提供三種解決辦法:佈局

   方法一:在你的activity中的oncreate中setContentView以前寫上這個代碼getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);設計

   方法二:在 項目的AndroidManifest.xml文件中界面對應的<activity>里加入 android:windowSoftInputMode="stateVisible|adjustResize",這樣會讓屏幕總體上移。若是加上的 是 android:windowSoftInputMode="adjustPan"這樣鍵盤就會覆蓋屏幕。code

   方法三:把頂級的layout替換成ScrollView,或者說在頂級的Layout上面再加一層ScrollView的封裝。這樣就會把軟鍵盤和輸入框一塊兒滾動了,軟鍵盤會一直處於底部。xml

在咱們的LinearLayout佈局外添加ScrollViewutf-8

 

方法三示例:get

 

由原來的:it

<?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">
                                                                            
    ......
                                                                                
</LinearLayout>

改成:io

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
                                                                    
    ......
                                                                        
</LinearLayout>
</ScrollView>
相關文章
相關標籤/搜索