Android RelativeLayout how to get a smaller window

I can not get Theme.Dialog activity. The problem is that I want only half the height.
Take a look at the image below.

Here is the manifest:

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

here is the 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:

Here is the screen

+3
source share
1 answer

This will do what you want. Keep in mind that you will get the full height of the window, so dividing by 2 will not be exactly half the size. I tried marking your placement to 3, and it looks good.

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;
    }
}
+2
source

All Articles