【问题标题】:How can I make my android dialog fullscreen?如何使我的 android 对话框全屏显示?
【发布时间】:2012-05-11 00:53:19
【问题描述】:

我已经尝试了所有我能找到的东西(在 stackoverflow 和网络上),但我无法将我的对话框设置为全屏。它有一个带有文本视图的滚动视图,当文本视图中的文本不多时,滚动视图不是全屏的。即使没有太多可见的文本,如何强制它全屏显示?

我这样创建对话框:

    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>

【问题讨论】:

    标签: java android textview scrollview fullscreen


    【解决方案1】:

    尝试将您的 对话框自定义布局 包装到 RelativeLayout 而不是线性布局。这对我有用。

    【讨论】:

    【解决方案2】:

    看起来您的 ScrollView 的高度设置为 wrap_content,我先尝试将其替换为 fill_parent

    以下是一些可能对您有所帮助的其他资源:

    How can I get a Dialog style activity window to fill the screen?

    我从未使用过setFlags() 方法,所以这可能会给您相同的结果。基本上尝试替换

    info.getWindow().setFlags(LayoutParams.FLAG_FULLSCREEN, LayoutParams.FLAG_FULLSCREEN);

    info.getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);

    或者,如果您想要更精确地控制高度,您可以创建一个布局参数实例,正如这里的第一个答案所述:

    How to make an alert dialog fill 90% of screen size?

    如果您想将其修改为略小于全屏,也可以使用此代码获取屏幕尺寸。

    Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();
    

    还有很多其他方法可以获取当前屏幕尺寸,这只是一个示例。祝你好运!

    【讨论】:

    • “info.getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);”做到了,非常感谢你:-)。
    【解决方案3】:

    您是否尝试过将 ScrollView 的 layout_height 设置为“match_parent”(您也可以将 LinearLayout 设置为“match_parent”,尽管我认为没有必要)?我猜当没有太多文本时它会缩小,因为它设置为“wrap_content”。试试这个:

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

    【讨论】:

    • 我试过了,但没有用。整个对话框的宽度和高度太小,我已经尝试了“fill_parent”和“match_parent”的各种组合。可能有什么我不知道的吗?需要设置或处理的额外内容?
    猜你喜欢
    • 2013-08-21
    • 2016-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-25
    • 1970-01-01
    • 2015-09-10
    • 1970-01-01
    相关资源
    最近更新 更多