Java 如何设置弹出窗口的屏幕自动适应水平屏幕的长度
我想让我的弹出窗口在水平长度上适合所有大小的移动屏幕?这里是我的Java和XML代码:So On按钮单击菜单2 Activity中出现的弹出窗口,我希望它在水平方向与屏幕匹配,垂直方向长度应为1000 爪哇: XML:Java 如何设置弹出窗口的屏幕自动适应水平屏幕的长度,java,android,xml,android-layout,Java,Android,Xml,Android Layout,我想让我的弹出窗口在水平长度上适合所有大小的移动屏幕?这里是我的Java和XML代码:So On按钮单击菜单2 Activity中出现的弹出窗口,我希望它在水平方向与屏幕匹配,垂直方向长度应为1000 爪哇: XML: 当您使用构造函数PopupWindow(查看内容视图,int-width,int-height,boolean focusable)时,尝试将参数width替换为LinearLayout.LayoutParams.MATCH\u PARENT。试试看。您可以在下面的功能中获得设
当您使用构造函数PopupWindow(查看内容视图,int-width,int-height,boolean focusable)
时,尝试将参数width
替换为LinearLayout.LayoutParams.MATCH\u PARENT
。试试看。您可以在下面的功能中获得设备“我的呼叫”的全宽
private int getDeviceWidth(Context context) {
WindowManager windowManager = (WindowManager)
context.getSystemService(Context.WINDOW_SERVICE);
int screenWidth = windowManager.getDefaultDisplay().getWidth();
return screenWidth;
}
并将该值传递给PopupWindow构造函数。是否传递getDeviceWidth?或屏幕宽度?调用函数,如int devicewwidth=getDeviceWidth(上下文);并在构造函数中传递这个变量。谢谢,我会尝试的
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#000"
android:alpha="0.95">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:paddingLeft="50dp"
android:paddingRight="50dp"
android:text="You reached a score of 10, you have a basic
knowledge!"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Button"
android:textColor="#ffffff"
android:textSize="20dp" />
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/trophy1"
android:layout_marginTop="22dp"
android:layout_below="@+id/textView3"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</LinearLayout>
private int getDeviceWidth(Context context) {
WindowManager windowManager = (WindowManager)
context.getSystemService(Context.WINDOW_SERVICE);
int screenWidth = windowManager.getDefaultDisplay().getWidth();
return screenWidth;
}