I’m having trouble positioning the layout elements. The AutoComplete in my TableLayout and the button after it are expanding the TableRow larger than the width of the screen. Anyone have an idea why? Below is my XML code as well as a picture of the problem.
Thanks in advance!!
<?xml version="1.0" encoding="utf-8"?>
<TableRow android:layout_width="fill_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView android:id="@+id/installation"
android:textSize="14sp" android:completionThreshold="3" />
</TableRow>
<TableRow android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:id="@+id/btn_find" android:text="@string/btn_find"></Button>
</TableRow>
<TableRow android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/error" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:paddingTop="20px"
android:textColor="#FF0000" />
</TableRow>
By default, widgets in a
TableRowhaveandroid:layout_width="wrap_content". That does not limit you to the size of the screen —wrap_contentmeans “wrap content”, not “wrap content but please don’t go off the edge of the screen, if you don’t mind”.In this case, you do not need to use a
TableLayoutand set ofTableRows, since you do not have a table.So, one approach is to use a
RelativeLayoutand have yourAutoCompleteTextViewuseandroid:layout_alignParentLeft="true"andandroid:layout_alignParentRight="true". That will pin it to the outer edges of theRelativeLayout, which you can size withandroid:layout_width=fill_parentto fill the screen.