2011-05-29 83 views
3

我無法讓Theme.Dialog活動變小。
問題是我只想要一半的高度。
看下面的圖片。android RelativeLayout如何獲得更小尺寸的窗口

這裏是清單:

<activity android:name=".PopUpSettings" 
      android:label="@string/app_name" 
      android:theme="@android:style/Theme.Dialog" 
      android:screenOrientation="portrait" 
      android:configChanges="keyboardHidden|orientation"> 

這裏是XML:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:paddingTop="15dp" 
    android:paddingLeft="15dp" 
    android:paddingRight="15dp" 
    android:paddingBottom="15dp" 
    > 

    <com.hellberg.ptppservice.imageedit.ColorPicker 
     android:id="@+id/color_picker_popup_settings" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     /> 

    <TextView android:id="@+id/exampeltext_popup_settings" 
     android:text = "This is the best app in the world" 
     android:textSize="20sp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@+id/color_picker_popup_settings" 
     /> 

    <Button android:id="@+id/fontleft_button_popup_settings" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentBottom="true" 
     /> 

    <Button android:id="@+id/fontright_button_popup_settings" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentBottom="true" 
     />  

    <TextView android:id="@+id/textlogo_popup_settings" 
     android:text = "©2011" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_alignParentBottom="true" 
     />  
</RelativeLayout> 

下面的畫面是:

Here is the screen

回答

2

這將做你想做的。請注意,您將獲得完整的窗口高度,因此用2分隔不會使其大小隻有一半。我試圖用3分開你的佈局,它看起來不錯。

public class DialogExampleActivity extends Activity { 

    private int mWindowHeight; 

    private static final int DIALOG_OPEN = 0; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     Display display = getWindowManager().getDefaultDisplay();   
     mWindowHeight = display.getHeight(); 

     showDialog(DIALOG_OPEN); 
    } 

    @Override 
    protected Dialog onCreateDialog(int id) { 
     Dialog myDialog = new Dialog(DialogExampleActivity.this); 

     switch (id) { 
     case DIALOG_OPEN: 
      myDialog.setContentView(R.layout.my_dialog);    
      myDialog.setCancelable(true); 

      RelativeLayout rr = (RelativeLayout) myDialog.findViewById(R.id.relative_layout); 
      LayoutParams params = rr.getLayoutParams();   
      params.height = mWindowHeight/3;   
      rr.setLayoutParams(params); 

      return myDialog; 
     } 

     return null; 
    } 
} 
+0

感謝它的工作。希望有更輕鬆的事情。現在我很高興謝謝。稍後當應用程序在Android Tab設備上運行時,我必須使用屏幕w/h計算更多 – Erik 2011-05-29 19:27:49