我创建一个自定义对话框如下:的Android定制对话框的LinearLayout大小相同的对话框BG图像
Dialog myDialog = new Dialog(context, R.style.Theme_Levels);
myDialog.setContentView(R.layout.levelselector);
myDialog.show();
风格使用:
<style name="Theme.Levels" parent="@android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowBackground">@drawable/dlgbg</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
布局xml文件:
<LinearLayout android:id="@+id/LevelSelector"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_gravity="bottom|center_horizontal"
android:paddingBottom="50dip"
>
<Button android:text="Easy"
android:id="@+id/btn_Easy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
我希望该按钮出现在对话框的底部中央(从底部起50dip填充),但它出现在对话框的左上角。
那是因为LinearLayout不知道对话框的宽度/高度,这是我在样式xml文件中使用的背景图像的大小。
问:如何知道对话框的宽度高度,以便LinearLayout的大小与对话框大小相同?
set layout_gravity for button。 –