tags:

views:

40

answers:

2

Hi All,

I need to size the top-most layout of my application dynamically (programmatically) based on information loaded from a configuration file.

Right now the in main.xml I have

 <?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout   
            android:id="@+id/LinearLayout01" 
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent" 
            xmlns:android="http://schemas.android.com/apk/res/android" 
            android:background="@drawable/background">
    </LinearLayout>

So I am looking for a way to change android:layout_width and layout_height programmatically.

Any help would be appreciated

RM

EDIT:

As per suggestions I have tried the following:

LinearLayout l2 = (LinearLayout)findViewById(R.id.LinearLayout07);
LinearLayout.LayoutParams params =  new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.FILL_PARENT,1);
l2.setLayoutParams(params);

But that gives me the following error when running:

Thread [<3> main] (Suspended (exception ClassCastException))    
FrameLayout.onLayout(boolean, int, int, int, int) line: 288 
FrameLayout(View).layout(int, int, int, int) line: 6133 
....
A: 

Check this out http://d.android.com/reference/android/widget/LinearLayout.LayoutParams.html

Ragunath Jawahar
I tried that but i think im doing somthing wrong .. ill post more code
Roman M
A: 
LinearLayout.LayoutParams params =
                new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.FILL_PARENT,1);


layout.setLayoutParams(params);

Where layout is your LinearLayout fetched with findViewById. Parameters for the width and height are fill_parent in my example with weight 1.

Instead of fill_parent options you can of course use the fixed size in pixels, or omit the weight if you don't want it.

Milan
thats what iv been trying to do, but the application crashes when i add this code ...this is the last two lines of stack:(Suspended (exception ClassCastException)) FrameLayout.onLayout(boolean, int, int, int, int) line: 288
Roman M
maybe the weight is doing something weird to the components inside. Can you try again but without the last parameter (without the 1 at the end). Try also adding the size in pixels instead of fill_parent.. Does the same error appear?
Milan