5

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 ?

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 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>
HardCoder
  • 3,026
  • 6
  • 32
  • 52

3 Answers3

6

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:

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. 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?

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!

Community
  • 1
  • 1
MattDavis
  • 5,158
  • 2
  • 23
  • 35
  • 1
    The "info.getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);" did it, thank you very much :-). – HardCoder May 01 '12 at 14:22
0

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)?. I'm guessing it shrinks when there isn't much text because it's set to "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>
Gophermofur
  • 2,101
  • 1
  • 14
  • 14
  • I tried that and it didn't work. The entire dialog is too small in width and height and I already tried various combinations of "fill_parent" and "match_parent". Is there maybe something to it that I don't know ? Something extra that needs to be set or taken care of ? – HardCoder May 01 '12 at 14:18
0

Try wrapping your dialog custom layout into RelativeLayout instead of Linear Layout. That worked for me.

Ayan
  • 8,192
  • 4
  • 46
  • 51
  • 2
    Please don't add the same answer to multiple questions. Answer the best one and flag the rest as duplicates. See [Is it acceptable to add a duplicate answer to several questions?](http://meta.stackexchange.com/q/104227) – Bhargav Rao Sep 23 '16 at 07:48