如何使我的Android对话框全屏显示? [英] How can I make my android dialog fullscreen?
问题描述
我已经尝试了所有可以找到的东西(在stackoverflow和网络上),但是我不知何故无法将对话框设置为全屏显示.它具有一个带有textview的scrollview,并且当textview中没有太多文本时,scrollview不会全屏显示.即使看不到太多文字,我怎么能将其强制为全屏显示?
I already tried all things I could find (on stackoverflow and the net) but I somehow cannot set my dialog to fullscreen. It has a scrollview with a textview in it, and when there is not much text in the textview the scrollview is not fullscreen. How can I force it to be fullscreen even when there is not much text visible ?
我这样创建对话框:
final TextView box;
final Dialog info = new Dialog(cx);
final ScrollView scroll;
info.setContentView(R.layout.dialoginfo);
info.setTitle("Info");
info.setCancelable(true);
info.getWindow().setFlags(LayoutParams.FLAG_FULLSCREEN, LayoutParams.FLAG_FULLSCREEN);
scroll = ((ScrollView) info.findViewById(R.id.scrollviewinfo));
scroll.setPersistentDrawingCache(ScrollView.PERSISTENT_NO_CACHE);
scroll.setScrollbarFadingEnabled(false);
box = (TextView) info.findViewById(R.id.infotext);
box.setText(text);
info.show();
这是xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/infolayout"
>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/ImageView01"
android:layout_weight="1.0"
android:id="@+id/scrollviewinfo">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/infolayout2">
<TextView android:layout_margin="5dip" android:layout_width="fill_parent" android:layout_height="wrap_content"
android:id="@+id/infotext"
android:textSize="8sp"
android:text=""/>
</LinearLayout>
</ScrollView>
</LinearLayout>
推荐答案
看起来您的ScrollView的高度设置为wrap_content
,我首先尝试将其替换为fill_parent
.
It looks like your ScrollView has its height set to wrap_content
, I'd first try replacing it with fill_parent
.
还有其他一些资源可以帮助您:
Here are some other resources that may help you:
我从未使用过setFlags()
方法,因此这可能会为您提供相同的结果.基本上尝试更换
I've never used the setFlags()
method, so this may give you the same results. Basically try replacing
info.getWindow().setFlags(LayoutParams.FLAG_FULLSCREEN, LayoutParams.FLAG_FULLSCREEN);
与
info.getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
或者,如果您想更精确地控制高度,则可以创建布局参数的实例,如此处的第一个答案所述:
Alternatively, if you wanted more exact control over the height, you can create an instance of layout params, as the first answer here describes:
如果要将其修改为比全屏略小,还可以使用此代码获取屏幕尺寸.
You can also use this code to get the screen size, if you wanted to modify it to be slightly smaller than full screen.
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
还有很多其他方法可以获取当前屏幕大小,这只是一个示例.祝你好运!
There are quite a few other ways to get the current screen size, too, this is just one example. Good luck!
这篇关于如何使我的Android对话框全屏显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!