嗨Guyies我使用简单的布局并动态创建它而不是XML文件。 我在其中添加按钮。所以任何人都可以让我如何将布局设置为垂直。 尝试了很多但根本没有工作。
答案 0 :(得分:0)
哦,是的,
< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
动态使用这个: -
btn1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
btn2.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
答案 1 :(得分:0)
只不过是:
LinearLayout layout = (LinearLayout) findViewById(R.id.your_layout);
layout.setOrientation(LinearLayout.VERTICAL);
在您的情况下,不是在R
中找到布局,而是使用您以编程方式创建的布局。
答案 2 :(得分:0)
您只需在LinearLayout
上致电setOrientation()
即可。默认方向是水平的。
LinearLayout layout = new LinearLayout(context);
layout.setOriantation(LinearLayout.VERTICAL);