Weight in LineraLayout with RelativeLayout child does not work



I try to apply weight on an android LinearLayout consists of 3 elements to a TextView occupy the most available space. The orientation of the layout is vertical and I apply the weight="1" on the TextView and no weight on the the other two elements in order to force them be placed at the bottom of the screen. However it does not work, as the "large" TextView occupies no space at all and the second element of the LinearLayout, which is a Relativelayout occupies the whole space. Here is the layout:



<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1" >

<TextView
android:id="@+id/txt_message"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:isScrollContainer="true"
android:maxLines="100000000" >

</TextView>

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >

<LinearLayout
android:id="@+id/answer_panel"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@color/my_color"/>

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:text="@string/answer_lbl">

</TextView>

<TextView
android:id="@+id/txt_answer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:isScrollContainer="true"
android:lines="6"
android:maxLines="100000000">
</TextView>

<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@color/my_color"/>

</LinearLayout>


<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:layout_alignParentBottom="true"
android:gravity="center">

<Button android:id="@+id/my_button"
android:layout_height="wrap_content"
android:focusable="false"
android:layout_width="wrap_content"
android:background="@color/my_button"
android:textSize="14sp"
android:textColor="@color/background_color"
android:text="@string/txt_my_button"/>


</LinearLayout>

</RelativeLayout>

</LinearLayout>


I have tried also to embeed the txt_message TextView in a Linearlayout but it does not change anything. How can I put the elements in the Relativelayout at the bottom of the screen and let the first TextView occupy the remaining space?


No comments:

Post a Comment