So I'm making a simple app, where you click a button, and it displays a popup with a random string from the button.
The problem is, when the pop up window is created, its a small box. like 100x100 or something. Here is the popup code. You can see I tried setting 550, and 750, as the size, if I put 70, and 550, it will work perfectly and be really small width, and stretched long wise. But after like 100dp, it goes back to square
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);
}
Here is my popup layout
<?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>
android:layout_width="wrap_content" android:layout_height="wrap_content"
尝试使用match_parent
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.