I have a problem similar to this question: Android Layout Weight
but it do not seems to have the same answer...
Inside a tablerow, I would like to display TextViews and EditTexts, where the TextViews take minimal size, and EditTexts share the remaining size:
'Size:[ edit1 ] x [ edit2 ] pixels'
I would guess the following implementation, but it displays:
'Size: [] x [] pixels'
What is wrong ?
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Size:" />
<EditText
android:id="@+id/desired_width"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="number" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="x" />
<EditText
android:id="@+id/desired_height"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="number" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="pixels" />
</TableRow>
I'm under 100 reputation and cannot answer my own question, but zapl is right, it's a problem oh behavior between TableRow and LinearLayout:
The solution if to create a LinearLayout inside the TableRow:
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Size:" />
<EditText
android:id="@+id/desired_width"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="number" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="x" />
<EditText
android:id="@+id/desired_height"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="number" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="pixels" />
</LinearLayout>
</TableRow>