2013-10-22 2 views
1

scrollView 안에 버튼이 있습니다. 버튼을 클릭하면 버튼을 클릭하자마자 팝업창이 나타나기 전 PopupWindow가 필요합니다.Android : PopupWindow 키보드 위의 빈 공간을 채우십시오.

final Button b = (Button) findViewById(R.id.button); 

     b.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 

       LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE); 
       View popupView = layoutInflater.inflate(R.layout.popup, null); 
       final PopupWindow popupWindow = new PopupWindow(popupView,WindowManager.LayoutParams.MATCH_PARENT,WindowManager.LayoutParams.MATCH_PARENT,true); 
       popupWindow.showAtLocation(v.getRootView(), Gravity.FILL, 0, 0); 

       //Bring soft keyboard up : NOT WORKING 
       final InputMethodManager mInputMethodManager = (InputMethodManager) getBaseContext().getSystemService(Context.INPUT_METHOD_SERVICE); 
       EditText editText = (EditText) popupView.findViewById(R.id.editText); 
       mInputMethodManager.showSoftInput(editText, 0); 

      } 
     }); 

내 레이아웃 XML은 다음과 같습니다 :

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

    <EditText 
     android:id="@+id/yourViewsEditText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:hint="Your Views" 
     > 
    </EditText> 



</RelativeLayout> 

내가 대신 wrap_content의 fill_parent를 시도, 그것은 전체 화면을 작성하여 시작합니다이 내 코드가 오늘날의 모습입니다. 이 같은 키보드의 높이를 얻을 수 enter image description here

+0

현재 어떻게 보이나요? – waqaslam

답변

2

아마도 다음과 같은 XML 레이아웃을 사용해보십시오 :

<?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:isScrollContainer="true" > 


    <EditText 
     android:id="@+id/yourViewsEditText" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:hint="Your Views" /> 

</RelativeLayout> 

키보드의 시작까지 자동으로 레이아웃의 높이를 설정해야합니다.

+1

굉장 .. 감사합니다 Waqas. 키보드를 위로 가져 왔습니까? popupWindow.setSoftInputMode (WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); \t \t \t \t popupWindow.setInputMethodMode (PopupWindow.INPUT_METHOD_NEEDED); – sharath

1

: 나는 이런 식으로 뭔가 달성하기 위해 노력하고

myLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 

       @Override 
       public void onGlobalLayout() { 
        // TODO Auto-generated method stub 
        Rect r = new Rect(); 
        parent.getWindowVisibleDisplayFrame(r); 

        int screenHeight = parent.getRootView().getHeight(); 
        int heightDifference = screenHeight - (r.bottom - r.top); 
        loadDialog(heightDifference); 

       } 
      }); 

을 한 다음 키보드의 높이와 폭으로 popupwindow를로드 할 수 있습니다 장치

public void loadDialog(int height) 
{ 
Display mDisplay = activity.getWindowManager().getDefaultDisplay(); 
int width = mDisplay.getWidth(); 

     //load the popup window with the height and width... 

} 
관련 문제