Might it be because as stated in the docs for setLayoutParams() "These 
supply parameters to the parent of this view specifying how it should be 
arranged." and in this case there's no parent of the view, so the attempted 
operation is not valid.
You might want to try the same with some child view and probably will 
work...

----- Original Message ----- 
From: "EvgenyV" <[email protected]>
To: "Android Developers" <[email protected]>
Sent: Sunday, January 11, 2009 1:13 AM
Subject: [android-developers] Change linear layout programmatically - 
problem


>
> Hi!
>
> I'm trying to change height layout from "wrap_content" to
> "fill_parent" from code. Using landscape mode.
> public class BBB extends Activity
> {
>    @Override
>     public void onCreate(Bundle savedInstanceState) {
>    super.onCreate(savedInstanceState);
>    setContentView(R.layout.bbb);
> LinearLayout layout = (LinearLayout)findViewById(R.id.mainZZZ);
>
>         LayoutParams params = new LayoutParams
> (LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
> layout.setLayoutParams(params);
>    }
> }
> I have bbb.xml layout file
> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
> android"
>    android:orientation="vertical"
>    android:id="@+id/mainZZZ"
>    android:layout_width="fill_parent"
> android:layout_height="wrap_content">
> </LinearLayout>
>
> Why the activity can't be loaded after run-time changes?
> Missing I something?
>
> Thanks in advance,
> Evgeny
>
> Stack error:
> 01-10 21:53:41.570: WARN/dalvikvm(1680): threadid=3: thread exiting
> with uncaught exception (group=0x40010e28)
> 01-10 21:53:41.581: ERROR/AndroidRuntime(1680): Uncaught handler:
> thread main exiting due to uncaught exception
> 01-10 21:53:41.841: ERROR/AndroidRuntime(1680):
> java.lang.ClassCastException: android.view.ViewGroup$LayoutParams
> 01-10 21:53:41.841: ERROR/AndroidRuntime(1680):     at
> android.widget.LinearLayout.measureVertical(LinearLayout.java:323)
> 01-10 21:53:41.841: ERROR/AndroidRuntime(1680):     at
> android.widget.LinearLayout.onMeasure(LinearLayout.java:275)
> 01-10 21:53:41.841: ERROR/AndroidRuntime(1680):     at
> android.view.View.measure(View.java:6621)
> 01-10 21:53:41.841: ERROR/AndroidRuntime(1680):     at
> android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2791)
> 01-10 21:53:41.841: ERROR/AndroidRuntime(1680):     at
> android.widget.FrameLayout.onMeasure(FrameLayout.java:208)
> 01-10 21:53:41.841: ERROR/AndroidRuntime(1680):     at
> android.view.View.measure(View.java:6621)
> 01-10 21:53:41.841: ERROR/AndroidRuntime(1680):     at
> android.widget.LinearLayout.measureVertical(LinearLayout.java:461)
> 01-10 21:53:41.841: ERROR/AndroidRuntime(1680):     at
> android.widget.LinearLayout.onMeasure(LinearLayout.java:275)
> 01-10 21:53:41.841: ERROR/AndroidRuntime(1680):     at
> android.view.View.measure(View.java:6621)
> 01-10 21:53:41.841: ERROR/AndroidRuntime(1680):     at
> android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:2791)
> 01-10 21:53:41.841: ERROR/AndroidRuntime(1680):     at
> android.widget.FrameLayout.onMeasure(FrameLayout.java:208)
> 01-10 21:53:41.841: ERROR/AndroidRuntime(1680):     at
> android.view.View.measure(View.java:6621)
> 01-10 21:53:41.841: ERROR/AndroidRuntime(1680):     at
> android.view.ViewRoot.performTraversals(ViewRoot.java:620)
> 01-10 21:53:41.841: ERROR/AndroidRuntime(1680):     at
> android.view.ViewRoot.handleMessage(ViewRoot.java:1103)
> 01-10 21:53:41.841: ERROR/AndroidRuntime(1680):     at
> android.os.Handler.dispatchMessage(Handler.java:88)
> 01-10 21:53:41.841: ERROR/AndroidRuntime(1680):     at
> android.os.Looper.loop(Looper.java:123)
> 01-10 21:53:41.841: ERROR/AndroidRuntime(1680):     at
> android.app.ActivityThread.main(ActivityThread.java:3742)
> 01-10 21:53:41.841: ERROR/AndroidRuntime(1680):     at
> java.lang.reflect.Method.invokeNative(Native Method)
> 01-10 21:53:41.841: ERROR/AndroidRuntime(1680):     at
> java.lang.reflect.Method.invoke(Method.java:515)
> 01-10 21:53:41.841: ERROR/AndroidRuntime(1680):     at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
> (ZygoteInit.java:739)
> 01-10 21:53:41.841: ERROR/AndroidRuntime(1680):     at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
> 01-10 21:53:41.841: ERROR/AndroidRuntime(1680):     at
> dalvik.system.NativeStart.main(Native Method)
>
>
>
>
> > 


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to