2016-01-25 285 views
0

ListView的元素我有一個包含一個ListView一個片段,我添加三個的EditText對和一個微調時,我選擇第二個EditText上的鍵盤顯示的預期,但我不能滾動列表視圖的最後兩個鍵盤可見時列表視圖中的其餘元素。軟鍵盤隱藏在片段

就好像列表視圖不能識別軟鍵盤是可見的,最後兩個剩餘的元素仍然在軟鍵盤後面。

下面是有問題的視圖的屏幕截圖和XML。

AndroidManifest:

<activity 
     android:name=".MainActivity" 
     android:label="@string/app_name" 
     android:windowSoftInputMode="adjustPan"> 

列表視圖:

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context=".MainActivity$PlaceholderFragment" 
android:background="@color/generic_grey"> 

<ListView 
    android:id="@+id/form_base_listview" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:divider="@null" 
    android:dividerHeight="0dp" 
    android:descendantFocusability="afterDescendants" 
    /> 
</RelativeLayout> 

多行查看:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="@color/white" 
android:paddingBottom="5dp"> 

<TextView 
    android:id="@+id/form_multi_txt" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/testing" 
    android:padding="10dp"/> 

<EditText 
    android:id="@+id/form_multi_edit" 
    android:layout_width="fill_parent" 
    android:layout_height="100dp" 
    android:layout_below="@+id/form_multi_txt" 
    android:layout_marginLeft="5dp" 
    android:paddingLeft="5dp" 
    android:paddingRight="5dp" 
    android:background="@drawable/edit_text_background" 
    android:layout_toLeftOf="@+id/form_multi_info_btn" 
    android:layout_toStartOf="@+id/form_multi_info_btn" 
    android:inputType="textMultiLine"/> 

<ImageButton 
    android:id="@+id/form_multi_info_btn" 
    android:layout_width="30dp" 
    android:layout_height="30dp" 
    android:scaleType="fitStart" 
    android:src="@drawable/form_row_info" 
    android:background="@android:color/transparent" 
    android:layout_below="@+id/form_multi_txt" 
    android:layout_alignParentRight="true" 
    android:layout_marginRight="10dp"/> 

</RelativeLayout> 

微調:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="@color/white" 
android:paddingBottom="5dp"> 

<TextView 
    android:id="@+id/form_select_txt" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/testing" 
    android:padding="10dp"/> 

<Spinner 
    android:id="@+id/form_select_spinner" 
    android:layout_width="fill_parent" 
    android:layout_height="44dp" 
    android:layout_below="@+id/form_select_txt" 
    android:layout_marginLeft="5dp" 
    android:spinnerMode="dialog" 
    android:layout_toLeftOf="@+id/form_select_info_btn" 
    android:layout_toStartOf="@+id/form_select_info_btn" 
    android:background="@android:drawable/btn_dropdown" 
    /> 

<ImageButton 
    android:id="@+id/form_select_info_btn" 
    android:layout_width="30dp" 
    android:layout_height="30dp" 
    android:scaleType="fitStart" 
    android:src="@drawable/form_row_info" 
    android:background="@android:color/transparent" 
    android:layout_below="@+id/form_select_txt" 
    android:layout_alignParentRight="true" 
    android:layout_marginRight="10dp"/> 

</RelativeLayout> 

微調中的觀點:

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/textViewSpinnerItem" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="@string/hello_world" 
style="@style/SpinnerTextViewItem" 
/> 

完整視圖: Complete View

查看與鍵盤:(不能滾動查看最後兩個元素) Keyboard visable

+0

使用softInputMode =調整鍋清單文件 –

+0

我已經在我的清單 –

回答

0

,那是因爲你的活動佈局必須一旦軟鍵盤打開就調整好,你沒有設置。你需要做的是編輯你的清單,並添加

android:windowSoftInputMode="adjustResize" 

正確的<activity>標記。這裏的Handling Input Method Visibility文檔的章節,你可能想要閱讀,看看你可以設置什麼樣的行爲windowSoftInputMode

+0

,並不工作,你的活動 –

1

把所有的標籤在一個實際的佈局和相對佈局在ScrollView。由於ScrollView只需要一個孩子。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="@color/white" 
android:paddingBottom="5dp"> 

<ScrollView 
android:layout_width="match_parent" 
android:layout_height="wrap_content"> 

<RelativeLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content"> 

<TextView 
    android:id="@+id/form_multi_txt" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/testing" 
    android:padding="10dp"/> 

<EditText 
    android:id="@+id/form_multi_edit" 
    android:layout_width="fill_parent" 
    android:layout_height="100dp" 
    android:layout_below="@+id/form_multi_txt" 
    android:layout_marginLeft="5dp" 
    android:paddingLeft="5dp" 
    android:paddingRight="5dp" 
    android:background="@drawable/edit_text_background" 
    android:layout_toLeftOf="@+id/form_multi_info_btn" 
    android:layout_toStartOf="@+id/form_multi_info_btn" 
    android:inputType="textMultiLine"/> 

<ImageButton 
    android:id="@+id/form_multi_info_btn" 
    android:layout_width="30dp" 
    android:layout_height="30dp" 
    android:scaleType="fitStart" 
    android:src="@drawable/form_row_info" 
    android:background="@android:color/transparent" 
    android:layout_below="@+id/form_multi_txt" 
    android:layout_alignParentRight="true" 
    android:layout_marginRight="10dp"/> 
</RelativeLayout> 
</ScrollView> 
</RelativeLayout>