2016-02-25 26 views
0

因此,我正在製作一個簡單的應用程序,在其中單擊按鈕,並從按鈕中顯示帶有隨機字符串的彈出式窗口。這個彈出窗口爲什麼只顯示爲一個小方格?

問題是,當彈出窗口被創建時,它的一個小盒子。像100x100什麼的。這是彈出式代碼。你可以看到我設置了550和750,因爲它的大小,如果我把70和550放在一起,它會很好地工作,並且寬度非常小,並且長得很明智。但是,像100dp後,它會回到原點

public void showPopup(View v){ 

     View popupView = getLayoutInflater().inflate(R.layout.popup_layout, null); 

     PopupWindow popupWindow = new PopupWindow(popupView, 550, 750); 

     // Example: If you have a TextView inside `popup_layout.xml` 
     TextView tv = (TextView) popupView.findViewById(R.id.tv); 

     String[] myString; 
     Resources res = getResources(); 
     myString = res.getStringArray(R.array.myArray); 

     String q = myString[rgenerator.nextInt(myString.length)]; 
     tv.setText(q); 



     // Initialize more widgets from `popup_layout.xml` 


     // If the PopupWindow should be focusable 
     popupWindow.setFocusable(true); 

     // If you need the PopupWindow to dismiss when when touched outside 
     popupWindow.setBackgroundDrawable(new ColorDrawable()); 



     // Get the View's(the one that was clicked in the Fragment) location 
     //v.getLocationOnScreen(location); 

     // Using location, the PopupWindow will be displayed right under anchorView 
     popupWindow.showAtLocation(v, Gravity.CENTER, 0, 0); 
    } 

這裏是我的彈出式佈局

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

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:id="@+id/tv" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" 
     android:textColor="#FFFF" 
     android:layout_gravity="center" /> 
</FrameLayout> 

回答

0
android:layout_width="wrap_content" android:layout_height="wrap_content" 

嘗試match_parent代替

相關問題