[英]How can I make my android dialog fullscreen?
I already tried all things I could find (on stackoverflow and the net) but I somehow cannot set my dialog to fullscreen. 我已经尝试了所有可以找到的东西(在stackoverflow和网络上),但是我不知何故无法将对话框设置为全屏显示。 It has a scrollview with a textview in it, and when there is not much text in the textview the scrollview is not fullscreen.
它具有一个带有textview的scrollview,并且当textview中没有太多文本时,scrollview不会全屏显示。 How can I force it to be fullscreen even when there is not much text visible ?
即使看不到太多文字,我怎么能将其强制为全屏显示?
I create the dialog like this: 我这样创建对话框:
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();
This is the xml: 这是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>
It looks like your ScrollView has its height set to wrap_content
, I'd first try replacing it with fill_parent
. 看起来您的ScrollView的高度设置为
wrap_content
,我首先尝试将其替换为fill_parent
。
Here are some other resources that may help you: 以下是一些可能对您有所帮助的资源:
How can I get a Dialog style activity window to fill the screen? 如何获得对话框样式活动窗口来填充屏幕?
I've never used the setFlags()
method, so this may give you the same results. 我从未使用过
setFlags()
方法,因此这可能会给您相同的结果。 Basically try replacing 基本上尝试更换
info.getWindow().setFlags(LayoutParams.FLAG_FULLSCREEN, LayoutParams.FLAG_FULLSCREEN);
with 与
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: 另外,如果您想更精确地控制高度,则可以创建一个布局参数实例,如此处的第一个答案所述:
How to make an alert dialog fill 90% of screen size? 如何使警报对话框填充屏幕大小的90%?
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!
祝好运!
Have you tried setting layout_height of the ScrollView to "match_parent" (and you can set the LinearLayout to "match_parent" too, though I don't think it's necessary)?. 您是否尝试过将ScrollView的layout_height设置为“ match_parent”(并且您也可以将LinearLayout设置为“ match_parent”,尽管我认为没有必要)? I'm guessing it shrinks when there isn't much text because it's set to "wrap_content".
我猜当没有太多文本时它会缩小,因为它设置为“ wrap_content”。 Try this:
尝试这个:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
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="match_parent"
android:orientation="vertical"
android:id="@+id/infolayout2">
...
</LinearLayout>
</ScrollView>
Try wrapping your dialog custom layout into RelativeLayout instead of Linear Layout. 尝试将对话框自定义布局包装到RelativeLayout中,而不是线性布局中。 That worked for me.
那对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.