У меня ниже RelativeLayout с кнопкой и LinearLayout.Я добавляю TextViews в LinearLayout, но, даже если я установил ориентацию по вертикали в атрибуте LinearLayout, содержимое LinearLayout становится горизонтальным.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<Button android:text="Add a server" android:id="@+id/addHost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="addHost"/>
<LinearLayout android:orientation="vertical"
android:id="@+id/listhosts"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/addHost" android:layout_weight="1">
</LinearLayout>
</RelativeLayout>
И программно я делаю так: -
LinearLayout linearLayout = (LinearLayout)findViewById(R.id.listhosts);
linearLayout.setOrientation(LinearLayout.VERTICAL);
TextView h = new TextView(this);
h.setText(line);
h.setId(index++);
linearLayout.addView(h);
Любая подсказка, где я ошибаюсь?
Ответ:
Сработало добавление строки ниже:
h.setLayoutParams (новые LayoutParams (LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));