2012-07-10 36 views
17

Hãy nói tôi có cách bố trí như sau:bố trí của màn hình di chuyển lên khi bàn phím được hiển thị

http://i47.tinypic.com/2vchnih.png

khi tôi bấm vào chỉnh sửa văn bản ở phía dưới tôi có được điều này:

http://i45.tinypic.com/352lym9.png

Như bạn có thể nhận thấy hình ảnh từ trên cùng đi lên trên và toàn bộ bố cục sẽ di chuyển. Đây là xml của tôi cho bố trí này:

<?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="#FFFFFF" > 

    <LinearLayout 
     android:id="@+id/header" 
     android:layout_width="fill_parent" 
     android:layout_height="75dp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true"   
     android:isScrollContainer="true" 
     android:background="@drawable/header" > 
    </LinearLayout> 

    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/scrollauthentication" 
     android:layout_below="@+id/header" 
     android:background="#FFFFFF" 
     android:fillViewport="true" > 

     <RelativeLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:background="#FFFFFF" 
      android:id="@+id/authenticationrelativelayout"> 

      <TextView 
       android:id="@+id/login" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_below="@+id/header" 
       android:layout_marginLeft="30dp" 
       android:layout_marginTop="20dp" 
       android:text="login" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:textColor="@color/lighter_orange" 
       android:textSize="28dp" /> 

      <TextView 
       android:id="@+id/usernameTextView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignLeft="@+id/login" 
       android:layout_below="@+id/login" 
       android:layout_marginTop="16dp" 
       android:text="username" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:textColor="@color/dark_gray" /> 

      <EditText 
       android:id="@+id/user" 
       android:layout_width="260dp" 
       android:layout_height="42dp" 
       android:layout_alignLeft="@+id/usernameTextView" 
       android:layout_below="@+id/usernameTextView" 
       android:background="@drawable/edittext_selector" 
       android:imeOptions="actionDone" 
       android:lines="1" 
       android:paddingLeft="10dp" /> 

      <TextView 
       android:id="@+id/passwordTextView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignLeft="@+id/user" 
       android:layout_below="@+id/user" 
       android:text="password" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:textColor="@color/dark_gray" /> 

      <EditText 
       android:id="@+id/password" 
       android:layout_width="260dp" 
       android:layout_height="42dp" 
       android:layout_alignLeft="@+id/passwordTextView" 
       android:layout_below="@+id/passwordTextView" 
       android:background="@drawable/edittext_selector" 
       android:imeOptions="actionDone" 
       android:inputType="textPassword" 
       android:lines="1" 
       android:paddingLeft="10dp" > 

       <requestFocus /> 
      </EditText> 

      <CheckBox 
       android:id="@+id/remembercheckBox" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignLeft="@+id/password" 
       android:layout_below="@+id/password" 
       android:layout_marginTop="37dp" 
       android:button="@drawable/checkbox_selector" 
       android:focusable="true" /> 

      <TextView 
       android:id="@+id/rememberText" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignBaseline="@+id/remembercheckBox" 
       android:layout_alignBottom="@+id/remembercheckBox" 
       android:layout_toRightOf="@+id/remembercheckBox" 
       android:text="Remember me" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:textColor="@color/dark_gray" /> 
     </RelativeLayout> 
    </ScrollView> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="30dp" 
     android:layout_below="@+id/scrollauthentication" 
     android:orientation="horizontal" > 

     <Button 
      android:id="@+id/loginButton" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@color/button_selected" 
      android:text="log in" 
      android:textColor="@drawable/textblack_selected" 
      android:textStyle="bold" > 
     </Button> 

     <Button 
      android:id="@+id/forgotten" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:background="@color/button_selected" 
      android:text="forgotten password" 
      android:textColor="@drawable/textblack_selected" 
      android:textStyle="bold" /> 
    </LinearLayout> 

</RelativeLayout> 

Và tôi cũng đã thiết lập này trong file manifest cho hoạt động này:

android:windowSoftInputMode="adjustPan" 

Vậy là có một cách để ngăn chặn bố trí của tôi từ di chuyển khi bàn phím được hiển thị? Cảm ơn bạn !!!!

+0

Kiểm tra liên kết này: http://stackoverflow.com/questions/9989130/page-scroll-when-soft-keyboard-poped-up –

+0

Tôi nghĩ rằng liên kết này sẽ giúp bạn. [Link] [1] [1]: http://stackoverflow.com/questions/5516216/how-to-avoid-soft-keyboard-pushing-up-my-layout Cảm ơn ... – user4232

+0

@YogeshSomani không có gì trong đó tôi chưa thử. và nó không hoạt động tốt như – adrian

Trả lời

10

tốt, tôi chưa đề cập đến bất kỳ "windowSoftInputMode" nào trong tệp kê khai của ứng dụng và nó chạy tốt. Màn hình không di chuyển lên khi bàn phím mở ra. Hãy thử phương pháp này - chỉ cần xóa tham số "windowSoftInputMode" khỏi tệp kê khai của bạn.

26

Hãy thử sử dụng

android:windowSoftInputMode="adjustPan|adjustResize" 

cho hoạt động này.

+0

Tôi đã thử.nó không tạo sự khác biệt – adrian

+0

Bạn có thể vui lòng hiển thị mã tệp kê khai của mình không? – SALMAN

+5

hãy thử điều này cho ScrollView của bạn android: isScrollContainer = "false" điều này có thể giúp bạn. – SALMAN

1

Hãy thử điều này:

android:windowSoftInputMode="adjustNothing" 
+1

Trong khi đoạn mã này được chào đón, và có thể cung cấp một số trợ giúp, nó sẽ được [cải thiện rất nhiều nếu nó bao gồm một lời giải thích] (// meta.stackexchange.com/q/114762) của * how * và * why * this giải quyết vấn đề. Hãy nhớ rằng bạn đang trả lời câu hỏi cho độc giả trong tương lai, không chỉ là người hỏi ngay bây giờ! Vui lòng [sửa] câu trả lời của bạn để thêm giải thích và đưa ra chỉ dẫn về những giới hạn và giả định được áp dụng. –

2

My EditText giữ di chuyển lên là tốt.

Thêm trọng lực vào Chỉnh sửa văn bản dường như giải quyết được sự cố. Bàn phím đang đẩy EditText của tôi lên, vì vậy tôi đã thêm trọng lực vào phần dưới cùng của Chỉnh sửa văn bản trong XML.

android:gravity=bottom 
0

Tôi đã có một windowsoftInputMode để ngăn chặn bàn phím từ khai mạc, vì vậy chỉ cần thêm đoạn mã bình luận

android: windowSoftInputMode = "stateHidden | adjustPan | adjustResize"

Các vấn đề liên quan