2014-10-02 8 views
1

나는이 문제에 대한 많은 해결책을 찾았지만 그들 중 누구도 나를 위해 일하지 못했습니다. 나는 PopupWindow를 Fragment 안에 보여주고 싶다. 이것은 내 코드입니다PopupWindow가 보이지 않음

LayoutInflater layoutInflater = LayoutInflater.from(getActivity()); 
View popupView = layoutInflater.inflate(R.layout.pop_up_cargando, null,false); 
this.popupWindow = new PopupWindow(popupView, popupView.getWidth(),popupView.getHeight()); 
this.popupWindow.setFocusable(true); 
int location[] = new int[2]; 
this.btnInventario.getLocationOnScreen(location); 
this.popupWindow.showAtLocation(this.btnInventario, Gravity.NO_GRAVITY, location[0], location[1] + btnInventario.getHeight()); // this.btnInventario is the button that calls this code 
this.popupWindow.update(0, 0, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 

그러나 PopupWindow는 나타나지 않습니다.

편집 :이 pop_up_cargando

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/popup_recomendar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#ffffff" 
    android:orientation="vertical" > 
    <ProgressBar 
     style="?android:attr/progressBarStyleHorizontal" 
     android:layout_width="180dp" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="15dp" 
     android:layout_marginRight="15dp" 
     android:layout_marginTop="20dp" 
     android:layout_gravity="center" 
     android:id="@+id/cargando"/> 
    <TextView 
     android:id="@+id/txtTexto" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="20dp" 
     android:layout_marginBottom="20dp" 
     android:layout_marginLeft="15dp" 
     android:layout_marginRight="15dp" 
     android:layout_gravity="center" 
     android:text="@string/vacio" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 
</LinearLayout> 

어떤 제안의 내용입니까? 내가 뭘 잘못하고있어? 귀하의 도움은 매우 감사하겠습니다.

+0

나는 popupWindow.showAtLocation을 사용하고 있습니다. 그것은 코드에 있습니다 – martinc

+0

'popupView.getWidth()'와'popupView.getHeight()'값이 0보다 큰지 확인하십시오. –

+0

@ G.T. 둘 다 0입니다 ... 통지하지 않았다. 어떻게 해결할 수 있습니까? – martinc

답변

1

popupView.getWidth()popupView.getHeight() 값은 뷰가 아직 그려지지 않았기 때문에 0과 같습니다.

보기의 높이을 요구하기 전에, 당신은 그것을 그려되었는지 확인해야합니다. 이 팽창 한 후 다음과 같은 메소드를 호출 할 수있는 경우 : 그 후

popupView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); 

,보기의 크기는 방법 getMeasuredWidth()getMeasuredHeight() 사용할 수 있습니다.

+0

도움을 주셔서 감사합니다. 해당 행을 추가했습니다. 이제는 높이와 너비에 대한 올바른 값을 취하고 있지만 팝업은 여전히 ​​나타나지 않습니다 ... – martinc

+0

마지막 두 줄을'popupWindow.show()'로 바꾸면 어떨까요? –

+0

Can not : "PopupWindow 유형에 대해 show() 메서드가 정의되지 않았습니다." – martinc