Итак, я делаю простое приложение, на которое вы нажимаете кнопку, и отображает всплывающее окно со случайной строкой от кнопки.Почему это всплывающее окно отображается только как маленький квадрат?
Проблема в том, что при всплывающем окне создается небольшая коробка. например, 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>