Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to set the absolute size of an Activity's Window?

Tags:

android

Is there a way to set a GUI screen (Activity) to be 200dip wide and 150dip high, either using XML or programmatically?

I found getWindow().setLayout(), but that only take predefined constants for width and height.

like image 670
zer0stimulus Avatar asked Dec 15 '10 20:12

zer0stimulus


People also ask

How can I get mobile screen width and height in android?

Display display = getWindowManager(). getDefaultDisplay(); Point size = new Point(); display. getSize(size); int width = size. x; int height = size.

How do you find the height of an activity?

I've found a way to know the exact height of my activity: if you have a view filling all the available screen behind the title bar and the task bar, just use View. getBottom() to get the real height of that activity.


3 Answers

You can use absolute numbers in Window.setLayout(), just like you can everywhere else you specify layout width and height. Sorry the doc isn't clear on this.

like image 165
hackbod Avatar answered Oct 02 '22 17:10

hackbod


WindowManager.LayoutParams params = getWindow().getAttributes();  
        params.x = 0;  
        params.height = 650;  
        params.width = totalWidth;  
        params.y = totalHeght/10;

        this.getWindow().setAttributes(params); 

may be it works...but make sure about the values...

like image 29
jettimadhuChowdary Avatar answered Oct 02 '22 17:10

jettimadhuChowdary


Just use a full screen layout, and inside define another layout that has the size you want. Kind of like this:

<?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">
    <LinearLayout android:layout_width="200dip" 
        android:layout_height="150dip">
        <Button android:text="Button"
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"/>
    </LinearLayout>
</LinearLayout>

I put a button in there just to show where the content goes.

like image 35
blindstuff Avatar answered Oct 02 '22 17:10

blindstuff