android RelativeLayout如何获得更小的窗口大小

时间:2011-05-29 13:54:29

标签: android relativelayout

我无法让Theme.Dialog活动变得更小 问题是我只想要一半的高度 看下面的图片。

这是清单:

 <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

1 个答案:

答案 0 :(得分: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;
    }
}