I have below RelativeLayout with a Button and LinearLayout. I am adding TextViews to LinearLayout but even though I have set orientation to vertical in LinearLayout attribute the content of LinearLayout is coming horizontal.
<?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>
And programatically I am doing like this:-
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);
Any clue where I am wrong?
Answer:
Adding below line worked:
h.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));