4

我一直在尋找這個問題的解決方案,但是我沒有找到任何可以解決我的問題的方法。顯示鍵盤時頁腳上升

我使用的RelativeLayout作爲我的主要佈局和我的頁腳是RelativeLayout的也一樣,我在互聯網上找到這些配置:

機器人:windowSoftInputMode =「adjustPan | adjustResize」

它適用於頁腳保持不變,但我的滾動不起作用,這是我的主要問題,我能做些什麼來解決它?

我的佈局:在AndroidManifest

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/background" 
    android:focusable="true" 
    android:fitsSystemWindows="true" 
    android:orientation="vertical" > 

    <ScrollView 
     android:id="@+id/scrollView1" 
     android:fillViewport="true" 
     android:isScrollContainer="true" 
     android:fitsSystemWindows="true" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

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

      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" > 

       <TextView 
        android:id="@+id/ttvp1" 
        style="@style/ttvPersonalizado" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/p1" /> 

       <TextView 
        android:id="@+id/ttvp2" 
        style="@style/ttvPersonalizadoDireito" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/p2" /> 
      </LinearLayout> 

      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" > 


       <EditText 
        android:id="@+id/edtP1" 
        style="@style/edtPersonalizado" 
        android:maxLength="5" 
        android:layout_height="wrap_content" 
        android:background="@drawable/edit_text_design" 
        android:ems="10" 
        android:inputType="numberDecimal" > 
       </EditText> 

       <EditText 
        android:id="@+id/edtP2" 
        style="@style/edtPersonalizado" 
        android:maxLength="5" 
        android:layout_height="wrap_content" 
        android:background="@drawable/edit_text_design" 
        android:ems="10" 
        android:inputType="numberDecimal" /> 

      </LinearLayout> 

      <TextView 
       android:id="@+id/ttvpim" 
       style="@style/ttvPersonalizado" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/pip3" /> 

      <EditText 
       android:id="@+id/edtPiP3" 
       style="@style/edtPersonalizado" 
       android:maxLength="5" 
       android:layout_height="wrap_content" 
       android:background="@drawable/edit_text_design" 
       android:inputType="numberDecimal" /> 

      <LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" > 

       <TextView 
        android:id="@+id/ttvExame" 
        style="@style/ttvPersonalizado" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:paddingRight="18dp" 
        android:text="@string/notaExame" /> 

       <CheckBox 
        android:id="@+id/chkExame" 
        style="@style/chkPersonalizado" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="40dp" 
        android:text="@string/exame" /> 
      </LinearLayout> 

      <LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" > 

       <EditText 
        android:id="@+id/edtExame" 
        style="@style/edtPersonalizado" 
        android:maxLength="5" 
        android:layout_height="wrap_content" 
        android:background="@drawable/edit_text_design" 
        android:ems="10" 
        android:enabled="false" 
        android:inputType="numberDecimal" 
        android:width="125dp" /> 

       <CheckBox 
        android:id="@+id/chkPersonalizado" 
        style="@style/chkPersonalizado" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/tecnologo" /> 
      </LinearLayout> 

      <TextView 
       style="@style/ttvPersonalizado" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/mediaFinal" /> 

      <EditText 
       android:id="@+id/edtMedia" 
       style="@style/edtPersonalizado" 
       android:maxLength="5" 
       android:layout_height="wrap_content" 
       android:background="@drawable/edit_text_design" 
       android:enabled="false" 
       android:inputType="numberDecimal" /> 

      <TextView 
       android:id="@+id/ttvStatus" 
       style="@style/ttvPersonalizado" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="" /> 

      <LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" > 

       <ImageButton 
        android:id="@+id/btnGerarMedia" 
        style="@style/btnMedio" 
        android:background="@drawable/shapebutton" 
        android:contentDescription="@string/gerarMedia" 
        android:src="@drawable/icone_calculadora" 
        android:text="@string/gerarMedia" /> 
      </LinearLayout> 
     </LinearLayout> 
    </ScrollView> 

    <RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="50dip" 
    android:layout_alignParentBottom="true" 
    android:background="@drawable/background_footer" 
    android:orientation="vertical" > 

    <com.google.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="fill_parent" /> 


</RelativeLayout> 

</RelativeLayout> 

我的活動配置:

<activity 
      android:name="br.com.media_universidades.visao.MediaCalculoActivity" 
      android:icon="@drawable/ic_launcher" 
      android:label="@string/umc" android:windowSoftInputMode="adjustPan|adjustResize"/> 

預先感謝您。

+2

將您的佈局添加到問題中,以便我們可以看到您正在處理的內容。 –

+0

部分你的佈局,並確認它有滾動視圖 –

+1

更改'android:windowSoftInputMode'值爲'android:windowSoftInputMode =「stateVisible | adjustResize'。希望它有幫助 – piotrek1543

回答

1

取決於哪個版本的Android上使用的是怎樣的佈局將有不同的解決方案:

<activity 
    android:name="br.com.media_universidades.visao.MediaCalculoActivity" 
       android:icon="@drawable/ic_launcher" 
       android:label="@string/umc" 
    android:windowSoftInputMode="adjustResize"> 

編輯:固定在上面的代碼爲透水答案我寫的是用這個

android:windowSoftInputMode="stateVisible|adjustResize"/> 

但有時你必須使用的onCreate代碼,迫使它()方法:

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

這裏是一個修復,這裏是doc

該設置必須是下表中列出的值之一,即 或一個「狀態...」值與一個「調整...」值的組合。 在任一組中設置多個值 - 多個「狀態...」值,例如 - 具有未定義的結果。個別值由豎線(|)分隔 。例如:

但我沒有正確閱讀OP問題,他滾動視圖不動。這需要添加到滾動視圖的OnGlobalLayoutListener()。

final View activityRootView = findViewById(R.id.activityRoot); 
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { 
@Override 
public void onGlobalLayout() { 
    Rect r = new Rect(); 
    //r will be populated with the coordinates of your view that area still visible. 
    activityRootView.getWindowVisibleDisplayFrame(r); 

    int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top); 
    if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard... 
     ... do something here 
    } 
} 
}); 

Here are some awesome way to do it。上面的代碼來自@Kachi。

+0

SA,這個解決方案只解決了滾動問題,但我的頁腳仍然與android:windowSoftInputMode =「stateVisible | adjustResize」,有什麼辦法滾動作品和頁腳不上去? –

+0

@RafaelChinelatoDelNero已經嘗試過,只是android:windowSoftInputMode =「adjustResize」>?這對我有用! –

+0

S A,當我只放「adjustResize」時,我的頁腳仍然上升,我不想要這樣的行爲。 –