我有一个简单的要求:我必须在对话框中放置一些图片(一些小分辨率,一些大分辨率)并全屏显示。
我试过了:
Dialog dialog = new Dialog(getActivity());
dialog.setContentView(R.layout.custom_dialog);
int picId = Integer.valueOf(webcamCursor.getString(webcamCursor
.getColumnIndex("_id")));
dialog.setTitle(webcamCursor.getString(webcamCursor
.getColumnIndex("City")));
image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.icon);
new DownloadPicTask().execute(Snippets.getUrlFromCat(picId, cat));
dialog.show();
我的布局是:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
>
<ImageView android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
/>
</LinearLayout>
当我在任何地方写下fill_parent时,对话框不应该全屏显示吗?
答案 0 :(得分:8)
试试:
dialog.getWindow().getAttributes().width = LayoutParams.FILL_PARENT;
希望它有所帮助。
答案 1 :(得分:0)
try this will work
//Grab the window of the dialog, and change the width
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
Window window = dialog.getWindow();
lp.copyFrom(window.getAttributes());
//This makes the dialog take up the full width
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
window.setAttributes(lp);