I have a horizontal LinearLayout containing a text box (search) and a toggle button. How can I get the search box to fill all the width less the width of a toggle box?
Visually:
[Wide Search Box][Toggle]
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout1">
<EditText
android:id="@+id/search_box"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="type to search titles"
android:inputType="text"
android:maxLines="1"
android:visibility="gone"
android:capitalize="none"
android:linksClickable="false"
android:autoLink="none"
android:autoText="true"
android:singleLine="true" />
<ToggleButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/toggleButton1"
android:textOff="ABC"
android:textOn="KMs" />
</LinearLayout
Add a
layout_weightattribute to theEditText, such as:I also modified the
layout_widthattributes, so the button wraps to it’s content and the text field fills the remaining space on the line. Adding weight to a child in aLinearLayouttells it to take up the remaining space, and the value of the weight determines how it will do so.HTH