2012-05-15 32 views
13

tôi có một cái nhìn với một số lĩnh vực (tên, email, mật khẩu, nút đăng ký):cách tạo chế độ xem android có thể cuộn khi bàn phím xuất hiện?

<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <ViewFlipper 
     android:id="@+id/viewflipper" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

     //Layouts 

    </ViewFlipper> 

</ScrollView> 

Khi tôi tập trung một trường EditText, bàn phím xuất hiện và được bao phủ các lĩnh vực thấp hơn trên xem. Vì vậy, tôi không thể nhìn thấy chúng khi bàn phím có mặt. Tôi muốn biết cách làm cho khung nhìn có thể cuộn được để tôi có thể thấy các trường dưới. Ngoài ra, cách làm cho chế độ xem cuộn tự động để hiển thị trường được lấy nét.

Trả lời

37

Bạn cần phải bao gồm android:windowSoftInputMode="adjustResize" thuộc tính cho hoạt động của bạn trong file AndroidManifest.xml - và sau đó Android nên làm như thay đổi kích thước cho bạn tự động:

<activity android:name="..." 
      ... 
      android:windowSoftInputMode="adjustResize"> 
    ... 
/> 
+1

Thực ra nó được đặt thành "adjustPan | adjustResize". Loại bỏ AdjustPan làm cho nó hoạt động. Cảm ơn! – Alexis

0

Các bạn đã thử này:

<ScrollView 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

<ViewFlipper 
    android:id="@+id/viewflipper" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 
    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/scroll_container"> 
     //Layouts 
    </ScrollView> 


</ViewFlipper> 

6

Tôi đã tạo tệp xml đơn giản, hy vọng đây là những gì bạn đang tìm kiếm.

bước 1. bạn có thể cuộn khi xuất hiện bàn phím.

bước 2. khi bạn nhấp vào Text-Field, nó sẽ xuất hiện trên bàn phím Focus/above.

<ScrollView android:id="@+id/ScrollView01" 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:fillViewport="true" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:weightSum="1.0" 
    android:layout_height="match_parent" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:id="@+id/l_layout"> 
    <EditText 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:id="@+id/editText1" 
     android:layout_marginTop="100dp"> 
     <requestFocus></requestFocus> 
    </EditText> 
    <EditText 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:id="@+id/editText2" 
     android:layout_marginTop="100dp"> 
     </EditText> 
    </LinearLayout> 
</ScrollView> 
+0

Tôi gặp sự cố với scrollview và fillViewport chỉ là những gì tôi cần. – AlexBrand

0

Trong trường hợp của tôi giải pháp @Aleks G không hoạt động. vì vậy, tôi đã giải quyết được sự cố của mình với

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    > 

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/registration_scroll_view" 
    android:layout_alignParentTop="true" 
    android:layout_above="@+id/btn_register_submit" 
    > 

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

     <!--This comment will be replaced 
      by your focusable views--> 

    </LinearLayout> 
</ScrollView> 

<Button 
    android:id="@+id/btn_register_submit" 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:layout_alignParentBottom="true" 
    android:background="@drawable/form_action_button_green" 
    android:gravity="center" 
    android:text="@string/submit" 
    /> 

</RelativeLayout> 
Các vấn đề liên quan