2013-07-10 34 views
4

我正在使用內部帶有TableLayout的LinearLayout的屏幕上工作,以顯示文本,一些EditText和一些按鈕。當軟鍵盤顯示時,在整個視圖中垂直滾動

問題是,在智能手機上,當我點擊佈局頂部的EditText時,底部的按鈕隱藏在軟鍵盤後面。讓按鈕再次出現的唯一方法是隱藏軟鍵盤。

enter image description here

是否有可能使我的佈局上的軟鍵盤的頂部滾動到我的觀點的按鈕,這樣用戶就可以看到軟鍵盤和按鈕上的底部?

我試着在TableLayout周圍使用ScrollView,但它不滾動到我的佈局的按鈕,所以用戶看不到底部。

這是我的佈局:

<?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="horizontal"> 

     <ScrollView 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 
       <LinearLayout 
        android:id="@+id/linearLayoutMain" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center_horizontal" 
        android:orientation="vertical" > 

        <include layout="@layout/login_container"/> 

        <LinearLayout 
         android:orientation="horizontal" 
         android:background="@drawable/_grey_rounded_bottom" 
         android:layout_width="match_parent" 
         android:layout_height="30dp"/> 

       </LinearLayout> 
     </ScrollView> 
</LinearLayout> 

在此先感謝。

回答

0

我有一個類似的看法,它爲我運行。看我的代碼:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    tools:context=".MainActivity" 
    android:orientation="vertical" > 

    <LinearLayout ... /> <!--Have an image that I want to stay on the top --> 

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

     <RelativeLayout ... > 
      <!-- EditText of username and EditText of password and a CheckBox --> 
      <LinearLayout 
       android:id="@+id/linearLayoutEntrar" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/checkBoxRecordarDatos" 
       android:gravity="center" 
       android:layout_marginTop="7dp" 
       android:weightSum="1.0"> 

       <Button 
        android:id="@+id/buttonEntrar" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="0.5" 
        android:text="@string/login_entrar" 
        android:textColor="@android:color/white" 
        android:textStyle="bold" 
        android:textSize="@dimen/textSize" 
        android:onClick="entrar" /> 

      </LinearLayout> 

      <LinearLayout 
       android:id="@+id/linearLayoutJugar" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/linearLayoutEntrar" 
       android:layout_marginTop="7dp" 
       android:gravity="center" 
       android:weightSum="1.0" > 

       <Button 
        android:id="@+id/buttonJugar" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="0.5" 
        android:onClick="jugar" 
        android:text="@string/login_jugar" 
        android:textColor="@android:color/white" 
        android:textSize="@dimen/textSize" 
        android:textStyle="bold" /> 

      </LinearLayout> 
     </RelativeLayout> 
    </ScrollView> 
</LinearLayout> 

試着改變身高,因爲我把每個佈局。如果不成功,我認爲問題是TableLayout,請儘量不要像我那樣使用它。

+0

我試着改變高度,但沒有奏效。我認爲TableLayout是可以的,因爲我改變了它像你使用的按鈕,並沒有工作。 –

+0

儘量不要使用'TableLayout'。每行可以使用一個'LinearLayout'('Label' +'EditText')。 – Lyd

+0

我改變了LineLayout的TableLayout與按鈕(如上面使用的那些),並沒有滾動到屏幕的底部... –

0

android:windowSoftInputMode="stateVisible|adjustPan"添加到清單中的活動標記中應該可以完成工作。

0
  1. 試機器人:windowSoftInputMode = 「adjustResize」
  2. 如果滾動視圖已經同級視圖元件,嘗試這種上滾動型

    機器人:layout_width = 「match_parent」 機器人:layout_height = 「0dp」 android:layout_weight =「1」

+0

不適用於片段adjustResize,我使用getActivity()。getWindow() .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);而不是似乎有用 – delive

相關問題