2014-01-29 4 views
0

I 다음 레이아웃 가지고로이드 화면 삽입

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/rootLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/blue_bg" > 

    <ScrollView 
     android:id="@+id/scrollView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fillViewport="true" > 

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


.... 
       <View 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="0.3" /> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="20dp" 
       android:src="@drawable/signup_illu_verificationcode" /> 

      <View 
       android:layout_width="match_parent" 
       android:layout_height="20dp" 
       android:layout_weight="0.0" /> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="5dp" 
       android:background="@android:color/white" 
       android:padding="5dp" 
       android:paddingLeft="25dp" 
       android:paddingRight="25dp" > 

       <LinearLayout 
        android:id="@+id/inputBox" 
        android:layout_width="match_parent" 
        android:layout_height="50dp" 
        android:layout_gravity="center" 
        android:layout_marginLeft="15dp" 
        android:layout_marginRight="15dp" 
        android:background="@drawable/input_box_idle" 
        android:gravity="center" 
        android:orientation="horizontal" > 

        <LinearLayout 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" > 

         <EditText 
          android:id="@+id/verificationCodeEditText" 
          style="@style/textOnBg" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:background="@android:color/transparent" 
          android:hint="- - - - -" 
          android:inputType="number" 
          android:textColor="#516063" 
          android:textColorHint="#b4c8cf" 
          android:textSize="25dp" > 
         </EditText> 
        </LinearLayout> 
       </LinearLayout> 
      </LinearLayout> 

      <View 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="0.7" /> 

      ... 

     </LinearLayout> 
    </ScrollView> 

</RelativeLayout> 

다음 코드 softkeboard 개구 검출 번 (아래도 조금 스크롤 가정

을)

public class PhoneVerifyYourNumbersActivity extends Activity { 

     private String mDisplayOptions[] = new String[3]; 
     private LinearLayout mInputBox; 
     private LinearLayout mContinueButton; 
     private TextView mVerifyByPhoneCallText; 

     private ScrollView mScrollView; 

     private EditText mVerificationCodeEditText; 
     private String mHash = null; 


     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.phone_verify_your_numbers); 

      mHash = getIntent().getStringExtra("Hash"); 

      initMembers(); 
      setOnClickListeners(); 
      initFieldsTexts(); 
      setKeyboardVisibilityListener(); 

     } 

.. 

     private void setKeyboardVisibilityListener() { 
      final View root = findViewById(R.id.rootLayout); 

      root.getViewTreeObserver().addOnGlobalLayoutListener(
        new OnGlobalLayoutListener() { 

         @Override 
         public void onGlobalLayout() { 
          // TODO Auto-generated method stub 

          int heightDiff = root.getRootView().getHeight() 
            - root.getHeight(); 
          if (heightDiff > 100) { // more than 100 pixels is 
                // probably a keyboard 
           // keyboard is shown 
           mInputBox 
             .setBackgroundResource(R.drawable.input_box_active); 
           //mScrollView.scrollTo(0, mScrollView.getBottom()); 
           mScrollView.scrollBy(0, +20); 
          } else { 
           // keyboard is not shown 
           mInputBox 
             .setBackgroundResource(R.drawable.input_box_idle); 
          } 
         } 
        }); 
     } 
} 

} 

내 매니페스트 :

<activity 
    android:name=".phone.PhoneVerifyYourNumbersActivity" 
    android:theme="@android:style/Theme.NoTitleBar" 
    android:windowSoftInputMode="stateHidden|adjustResize" /> 

이상한 동작은 사용자가 editText에 입력을 입력 할 때마다

스크롤이 1-2dps 아래로 이동한다는 것입니다. 무엇이 이것을 일으킬 수 있습니까?

나는이 mScrollView.scrollBy(0, +20); 여러 번

하지만 내가 한 번 그렇게 할 수있는 방법을 어떻게 됐을까?

(부울 플래그 isMovedAlready을 추가하는 것 외에는 영리한 아이디어가 있습니까?)

답변

0

mScrollView.scrollBy()px (픽셀)이 아닌 dp입니다. 먼저 dp를 px로 계산하는 것이 좋습니다.
하지만 뭔가 다른 것을 원한다고 생각합니다. 이 같은 :이`한 번만 키보드 아웃 후

View v = findViewById(R.id.verificationCodeEditText); 
mScrollView.scrollTo(0, v.getBottom()+10);//or similar 
+0

하지만라고 onGlobalLayout'되지 않는 이유는 무엇입니까? editText에 대한 모든 입력 삽입에 있지 않습니까? –

+1

나는 이것에 관해 확실하지 않다. 특히 모든 안드로이드 버전을위한 것은 아닙니다. 그러나 다른 이유로 호출 될 수도 있습니다. '전역 레이아웃 상태 또는 뷰 트리 내의 뷰 가시성이 바뀔 때 호출되는 콜백 메소드 '이므로 뷰/뷰 레이아웃 변경 액션이 거의 모두 호출 될 수 있습니다. –

0
// try to add one properties on AndroidManifest.xml Activity declaration like below. 
**AndroidManifest.xml** 
<activity 
    android:name="PhoneVerifyYourNumbersActivity" 
    android:windowSoftInputMode="stateHidden|adjustPan"> 
</activity> 
+0

내 현재 매니페스트를 추가했습니다. 키보드가 꺼진 후에 한 번만 호출되는'onGlobalLayout'이 아닌가? editText에 대한 모든 입력 삽입에 있지 않습니까? –