2012-05-01 17 views
4

我已經嘗試了所有可以找到的東西(在stackoverflow和網上),但我不知怎麼辦不能將我的對話框設置爲全屏。它有一個帶有文本視圖的滾動視圖,當文本視圖中沒有太多文本時,滾動視圖不是全屏。即使沒有太多可見的文字,我如何強制它全屏顯示?如何讓我的android對話框全屏?

我創建對話框如下:

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> 

回答

6

它看起來像你的滾動型有其高度設置爲wrap_content,我第一次嘗試用fill_parent替換它。

下面是其他一些資源,可以幫助您:

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

我從來沒有使用setFlags()方法,所以這可能給你相同的結果。基本上嘗試

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

或者更換

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

,如果你想在高度更精確的控制,您可以創建佈局則params的一個實例,作爲第一個答案在這裏描述:

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(); 

還有其他方法可以獲得當前的屏幕尺寸,這只是一個例子。祝你好運!

+1

「info.getWindow()。setLayout(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);」做到了,非常感謝你:-)。 – HardCoder

0

你有沒有嘗試設置了滾動的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> 
+0

我試過了,它沒有工作。整個對話框的寬度和高度都很小,我已經嘗試過「fill_parent」和「match_parent」的各種組合。有沒有我可能不知道的東西呢?有什麼額外的東西需要設置或照顧? – HardCoder

0

嘗試將您的對話框自定義佈局改爲RelativeLayout而不是Linear Layout。這對我有效。

+2

請不要對多個問題添加相同的答案。回答最好的一個,並將其餘標記爲重複。請參閱[是否可以爲幾個問題添加重複答案?](http://meta.stackexchange.com/q/104227) –

+0

@BhargavRao當然,請記住這一點。 – Ayan