2013-07-05 24 views
1

Android 2.3.3如何使一個活動(使用Theme.dialog顯示)佔據大部分屏幕 - Android

我有一個活動,即使用下面的代碼顯示。

<activity android:name="com.xx.xxx.CombinationActivity" 
    android:label="" 
    android:theme="@android:style/Theme.Dialog">    
</activity> 

這裏的佈局:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="center" 
    android:gravity="center" 
    android:background="#000000" 
    android:orientation="vertical" > 


    <!-- Beginner/Intermediate and so on --> 
    <TextView 
     android:id="@+id/textview_choose_level_main_title_1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_horizontal" 
     android:text="@string/text_choose_level_main_title_1" 
     android:textColor="#FFFFFF" 
     android:layout_marginBottom="20dp" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <TextView 
     android:id="@+id/textview_choose_level_1_title" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_horizontal" 
     android:text="@string/text_choose_level_1_default_title" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="#FFFFFF" /> 

    <TextView 
     android:id="@+id/textview_choose_level_1_range" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_horizontal" 
     android:text="@string/text_choose_level_1_default_range" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="#FFFFFF" /> 

    <SeekBar 
     android:id="@+id/seekbar_choose_level_1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="20dp" 
     android:max="100" /> 

    <TextView 
     android:id="@+id/textview_choose_level_empty" 
     android:layout_width="match_parent" 
     android:layout_height="20dp" 
     android:gravity="center_horizontal" 
     android:text="" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="#FFFFFF" /> 


    <!-- 2/3/4/5 --> 
    <TextView 
     android:id="@+id/textview_choose_level_main_title_2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_horizontal" 
     android:text="@string/text_choose_level_main_title_1" 
     android:textColor="#FFFFFF" 
     android:layout_marginBottom="20dp" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <TextView 
     android:id="@+id/textview_choose_level_2_title" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_horizontal" 
     android:text="@string/text_choose_level_1_default_title" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="#FFFFFF" /> 

    <TextView 
     android:id="@+id/textview_choose_level_2_range" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_horizontal" 
     android:text="@string/text_choose_level_1_default_range" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="#FFFFFF" /> 

    <SeekBar 
     android:id="@+id/seekbar_choose_level_2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="20dp" 
     android:max="100" /> 

</LinearLayout> 

當我運行應用程序,我得到的東西顯示在第一張圖像。我需要它作爲第二個圖像。

在此先感謝..

現在是什麼:

enter image description here

我想要什麼:

enter image description here


回答:::

對於那些正在尋找類似解決方案的人來說,我從@Marko評論中找到了答案。感謝馬爾科..

這裏是鏈接:click here

這裏是解決方案:

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.your_layout); 

    getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); 
} 
+0

你可以把話whaat你想要什麼?無法看到你的形象? –

+1

http://stackoverflow.com/questions/1362723/how-can-i-get-a-dialog-style-activity-window-to-fill-the-screen似乎像mathias答案是你想要的一個 –

+0

當我運行應用程序,我得到中間的活動,寬度等於任何文本視圖的文本。我需要它佔據整個屏幕,10dp的餘量。 –

回答

3

在你的活性,其具有Theme.Dialog樣式集,這樣做:

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.your_layout); 

    getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); 
} 
0

我只是猜測你想要什麼..

我想你想的活動,以填補你的屏幕

試試這個代碼

android:layout_width="fill_parent" 

代替

android:layout_width="match_parent" 
+0

但他們都這樣做,對不對?我猜,fill_parent已被棄用,我們建議使用match_parent –

0

使用

android:layout_width="match_parent" 
android:minWidth="1000dp" 

您的對話框現在會充滿整個屏幕寬度。

相關問題