2012-01-08 58 views
8

我有一個活動來編輯一些頂部酒吧文本一個EditText視圖在滾動視圖內的多行模式。在底部的另一個視圖與2個按鈕。我想要達到的目的是編輯底部欄位於軟鍵盤下方的文本。在清單中使用android:windowSoftInputMode =「adjustPan」很容易。問題在於如果edittext變得足夠大並且有多行,那麼在編輯頂部欄時它將消失。這隻在使用adjustPan模式時發生。但最糟糕的是,我認爲這是一個錯誤,當光標位於edittext視圖的末尾時,並且使用D-Pad操縱桿向上滾動,所有佈局都被拉到頂部。Android EditText多行與SoftInputMode adjustPan

這是一個沒有重點的EditText屏幕:http://i.stack.imgur.com/pFadV.png

當錯誤與滾動發生,出現這種情況:http://i.stack.imgur.com/eS8PP.png

我的佈局如下:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@color/BackgroundGray" 
    android:gravity="top|center" 
    android:orientation="vertical" 
    android:windowSoftInputMode="adjustPan" > 

    <RelativeLayout 
     android:id="@+id/top_bar" 
     android:layout_width="fill_parent" 
     android:layout_height="45dip" 
     android:layout_alignParentTop="true" 
     android:background="@drawable/top_bar" 
     android:focusable="true" 
     android:focusableInTouchMode="true" > 

     <ImageView 
      android:id="@+id/bar_item_priority" 
      android:layout_width="4dip" 
      android:layout_height="34dip" 
      android:layout_alignParentLeft="true" 
      android:layout_centerVertical="true" 
      android:contentDescription="@string/priority" /> 

     <EditText 
      android:id="@+id/bar_title" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_marginLeft="6dip" 
      android:background="@android:color/transparent" 
      android:fadingEdge="vertical" 
      android:gravity="center_vertical|left" 
      android:hint="@string/default_title" 
      android:inputType="text|textCapSentences" 
      android:paddingLeft="10dip" 
      android:textColor="#f3f3f3" 
      android:textColorHint="#20ffffff" 
      android:textSize="20dip" 
      android:textStyle="bold" > 
     </EditText> 
    </RelativeLayout> 

    <View 
     android:id="@+id/main_top_bar_shadow" 
     android:layout_width="fill_parent" 
     android:layout_height="1dip" 
     android:layout_below="@+id/top_bar" 
     android:background="@color/TopBarShadow" /> 

    <LinearLayout 
     android:id="@+id/meta_bar" 
     android:layout_width="fill_parent" 
     android:layout_height="25dip" 
     android:layout_below="@+id/main_top_bar_shadow" 
     android:background="#313435" 
     android:descendantFocusability="blocksDescendants" > 

     <TextView 
      android:id="@+id/meta_date_modified" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:gravity="center_vertical|left" 
      android:paddingLeft="10dip" 
      android:paddingRight="10dip" 
      android:paddingTop="6dip" 
      android:shadowColor="#1d1d1d" 
      android:shadowDx="1" 
      android:shadowDy="1" 
      android:shadowRadius="2" 
      android:text="@string/default_date" 
      android:textColor="#9d9d9d" 
      android:textSize="12dip" 
      android:textStyle="bold" > 
     </TextView> 
    </LinearLayout> 

    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_above="@+id/bottom_bar" 
     android:layout_below="@+id/meta_bar" 
     android:fillViewport="true" 
     android:scrollbarSize="2dip" 
     android:scrollbarThumbHorizontal="@drawable/scrollbar" 
     android:scrollbarThumbVertical="@drawable/scrollbar" 
     android:scrollbars="vertical" > 

     <view 
      android:id="@+id/note" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@android:color/transparent" 
      android:capitalize="sentences" 
      class="home.greven.notes.NoteEditor$LinedEditText" 
      android:fadingEdge="vertical" 
      android:gravity="top" 
      android:paddingBottom="8dip" 
      android:paddingLeft="11dip" 
      android:paddingRight="11dip" 
      android:paddingTop="8dip" 
      android:textSize="16sp" > 
     </view> 
    </ScrollView> 

    <View 
     android:id="@+id/bottom_bar_shadow" 
     android:layout_width="fill_parent" 
     android:layout_height="1dip" 
     android:layout_above="@+id/bottom_bar" 
     android:background="@color/TopBarShadow" 
     android:focusable="false" 
     android:focusableInTouchMode="false" /> 

    <LinearLayout 
     android:id="@+id/bottom_bar" 
     android:layout_width="fill_parent" 
     android:layout_height="40dip" 
     android:layout_alignParentBottom="true" 
     android:background="@drawable/bottom_buttons_bar" 
     android:descendantFocusability="blocksDescendants" > 

     <Button 
      android:id="@+id/bottom_bar_button_plaintext" 
      style="@style/NoteEditorButtonText" 
      android:layout_width="0.0dip" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:layout_margin="4dip" 
      android:layout_weight="0.5" 
      android:background="@drawable/small_blue_buttonstates" 
      android:text="@string/plain_text" /> 

     <Button 
      android:id="@+id/bottom_bar_button_checklist" 
      style="@style/NoteEditorButtonText" 
      android:layout_width="0.0dip" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:layout_margin="4dip" 
      android:layout_weight="0.5" 
      android:background="@drawable/small_gray_buttonstates" 
      android:onClick="toChecklist" 
      android:text="@string/checklist" /> 
    </LinearLayout> 

</RelativeLayout> 

如果我在android:windowSoftInputMode中使用adjustResize一切正常,但編輯時底部欄會顯示,這是我不想發生的事情。我認爲這個滾動問題是一個Android錯誤。任何幫助將非常感激!

回答

2

我在底部的按鈕也有同樣的問題。經過幾天的谷歌搜索,我發現這是由於缺少

android:isScrollContainer="false" 

在ScrollView。

的Android文件提及此

設置此如果視圖將作爲滾動容器,meaing該 它可以調整爲縮小其整體窗口,以便將有用於將輸入方法 空間。

編輯: 還要檢查這個Answer

+0

感謝您的答覆,但與d-墊滾動時它仍然沒有怪異的行爲。 – greven 2012-02-29 18:19:21

+0

其實我沒有在D-pad中測試過這段代碼,但是其他設備並沒有顯示出相同的結果。 – 2012-03-01 05:17:01

+0

我唯一遇到的問題是使用D-Pad滾動時,只有在顯示軟鍵盤的情況下。除此之外,是的,這個解決方案可以工作,但是這個錯誤依然存在。 – greven 2012-03-01 19:34:06