Android 对话框主题活动宽度
我有一个使用对话主题的活动Android 对话框主题活动宽度,android,android-relativelayout,Android,Android Relativelayout,我有一个使用对话主题的活动 <activity android:name=".GamePreviewDialog" android:theme="@android:style/Theme.Dialog" android:label="Chess Set Preview"> 在onCreate()方法之后,您可以获得高度和宽度。因此,结果表明,这不是因为对话框主题,而是因为它是一个相对值,并且在onResume时不知道宽度。要解决此问题,请使用Vie
<activity android:name=".GamePreviewDialog"
android:theme="@android:style/Theme.Dialog"
android:label="Chess Set Preview">
在
onCreate()
方法之后,您可以获得高度和宽度。因此,结果表明,这不是因为对话框主题,而是因为它是一个相对值,并且在onResume时不知道宽度。要解决此问题,请使用View.post()方法在设置视图后执行设置代码。在此处找到此解决方案当您设置布局宽度填充父项时,您可以获得屏幕大小,即您现在的视图宽度如何?我尝试在布局对象上调用getWidth(),它返回0。您可以在activity类的onclick()方法中获得高度和宽度。我也面临这个问题,但我用上面的解决方案得到了解决方案。你们并没有回答我的问题,怎么回答?对什么调用getWidth()?在什么OnClick()上?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/gamePreviewMainLayout"
android:background="@color/game_background">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/gamePreviewButtonView"
android:id="@+id/gamePreview"
android:background="@color/game_background">
</RelativeLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="@+id/gamePreviewButtonView"
android:background="@color/background">
<Button
android:text="Close"
android:id="@+id/previewCloseBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/chess_mates_btn">
</Button>
</LinearLayout>
</RelativeLayout>
getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);