Layout orientation in code
问题 I have this code in my application: LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT); and I just want to set the orientation of the LinearLayout to vertical. The equivalent in XML is: android:orientation="vertical" How can I do it in the code, without XML? 回答1: You can't change LinearLayout 's orientation using its LayoutParams . It can be done only with a LinearLayout object. LinearLayout layout = /* ... */; layout.setOrientation(LinearLayout