Android: How to set header's height or width in terms of screen

I am trying to make an application. It contains multiple activities which all have same header and footer. I want that these header and footer should look exactly same on every screen in terms of height. So i defined android:layout_height="20dp" in each Header and Footer. But it is not looking same in each activity, when number of entities (button) are more in field, size of header is reduced and when there is nothing in the field size works fine. So i thought that i should define Height or Width in terms of screen. So can anyone tell me how to define size of entities in terms of screen of device. I know how to get screen size

Display displayScreen = ((WindowManager) getSystemService(HomeActivity.WINDOW_SERVICE)).getDefaultDisplay();
        int layoutWidth = displayScreen.getWidth();
        int layoutHeight = displayScreen.getHeight();

and this is code of header

<LinearLayout android:id="@+id/llheader" android:layout_width="fill_parent" android:layout_height="20dp"
    android:layout_weight="1">
    <RelativeLayout android:id="@+id/relativeLayout1" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:layout_gravity="center"> <!--header -->
        <TextView android:id="@+id/txt_header" android:layout_width="wrap_content" android:layout_centerHorizontal="true"
            android:layout_centerVertical="true" android:layout_height="wrap_content" />
    </RelativeLayout>
</LinearLayout>

But don't know how to use that in defining height or width from java file. So please tell me the formatting of java code how to define size of anything with respect to screen.

Answers


<RelativeLayout> <header> <body> <!-- set layout_above and layout_below to footer's and header's id, respectively --> <footer> </RelativeLayout>


Try it...

    Display display =((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();

    int width = display.getWidth();

    int height=display.getHeight();
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(width/10, height/10);

    todostextview.setLayoutParams(layoutParams);

Give desired value in layoutparams


Need Your Help

Use MSDeploy to copy an executable to a server and to then run same

.net msdeploy

I've got MSDeploy/WebDeploy working a treat to update my web applications - this resolves about 90% of my deployment issues for the things I've got set up so far.

How to analyze a memory leak in Java 1.3

java memory memory-leaks weblogic solaris

I have a WebLogic 7 server, running under j2sdk1_3 on a Solaris platform.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.