Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 对话框主题活动宽度_Android_Android Relativelayout - Fatal编程技术网

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);