baudic_j baudic_j - 2 months ago 16
Android Question

layout_weight isn't working properly

I'm creating a simple layout in Android and I have a problem when displaying.
The fact is that all the elements are not displayed. The fact is there are just the calendar and the timespiker but there are not the others.

This is my code

<LinearLayout
android:id="@+id/sms_linear_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:gravity="center_horizontal"
android:orientation="vertical"
android:weightSum="8">


<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@string/sms_id_sms_pro" />

<EditText
android:id="@+id/sms_id_sms_pro"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@string/sms_nb_remainning" />

<EditText
android:id="@+id/sms_nb_remainning"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@string/sms_name_sender" />


<EditText
android:id="@+id/sms_name_sender"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:maxLength="11" />

<CalendarView
android:id="@+id/sms_calendar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>

<TimePicker
android:id="@+id/sms_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>

</LinearLayout>


and this is the result : my result

Answer

Assign 0dp value to height to all views so that layout weight can be adjusted

android:layout_height="0dp"