ダイアログ テーマを使用するアクティビティがあります。
<activity android:name=".GamePreviewDialog"
android:theme="@android:style/Theme.Dialog"
android:label="Chess Set Preview">
ダイアログの幅を取得する方法がわかりません。通常、ダイアログでない場合は、レイアウトで getWidth() を使用します。ただし、これでそれを行うとうまくいきません。
<?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>
contentView が他の投稿で提案されているように設定された後、これを呼び出してみました。プログラムで幅を取得する方法についてのアイデアはありますか?
getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);