平板电脑上弹出窗口的显示是错误的



我目前正在构建一个弹出窗口,该窗口应显示两行标签和按钮,允许用户查看两个视频。

我在布局上有困难。这是弹出式布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@color/layout_background_start">
<TextView
android:id="@+id/spacer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_alignParentLeft="true"
android:textSize="5dp"
android:textStyle="bold"
android:text=""/>
<TextView
android:id="@+id/general_video_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_alignParentLeft="true"
android:layout_below="@+id/spacer1"
android:textSize="20dp"
android:textStyle="bold"
android:text="Single-Player Tutorial"/>
<Button
android:id="@+id/general_video_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dp"
android:layout_alignParentRight="true"
android:layout_toRightOf="@id/general_video_title"
android:text="See Video"/>
<TextView
android:id="@+id/spacer2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_alignParentLeft="true"
android:layout_below="@id/general_video_button"
android:textSize="5dp"
android:textStyle="bold"
android:text=""/>
<TextView
android:id="@+id/multiplayer_video_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_alignParentLeft="true"
android:textSize="20dp"
android:textStyle="bold"
android:layout_below="@+id/spacer2"
android:text="Multiplayer Tutorial"/>
<Button
android:id="@+id/multiplayer_video_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dp"
android:layout_alignParentRight="true"
android:layout_toRightOf="@id/multiplayer_video_title"
android:layout_below="@+id/general_video_button"
android:text="See Video"/>
</RelativeLayout>

这是显示主活动中弹出的代码:

LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = inflater.inflate(R.layout.videos_popup, null);
// create the popup window
int width = LinearLayout.LayoutParams.WRAP_CONTENT;
int height = LinearLayout.LayoutParams.WRAP_CONTENT;
boolean focusable = true; // lets taps outside the popup also dismiss it
final PopupWindow popupWindow = new PopupWindow(popupView, width, height, focusable);
// show the popup window
popupWindow.showAtLocation(m_PlanesLayout, Gravity.CENTER, 0, 0);

我正在使用模拟器来测试不同手机或平板电脑弹出窗口的显示。问题是在平板电脑上;参见视频";按钮变得很大;wrap_ content";布局中的设置。弹出窗口似乎在某种程度上尊重相对于屏幕宽度的最小尺寸,并且按钮尺寸被调整以获得该最小尺寸。

有人能帮忙吗?

是的,它不受wrap_content的约束,因为它在TextView和屏幕右边缘之间拉伸:

android:layout_alignParentRight="true"
android:layout_toRightOf="@id/multiplayer_video_title"

相关内容

最新更新