问题
So i have a tablelayout in android with some table rows. In each row i have a textview and an edittext. My setup looks like:
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="10dp"
android:stretchColumns="3" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_marginBottom="5dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:background="@drawable/vnosnopolje" >
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Up. ime"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/uporabnisko_ime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:background="@drawable/round_corners"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:paddingLeft="3dp"
android:layout_marginLeft="5dp"
android:ems="10"
android:inputType="text" >
<requestFocus />
</EditText>
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_marginBottom="5dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:background="@drawable/vnosnopolje" >
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Geslo"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/geslo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:background="@drawable/round_corners"
android:inputType="textPassword"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:paddingLeft="3dp"
android:layout_marginLeft="5dp"
android:ems="10" >
</EditText>
</TableRow>
</TableLayout>
It all works fine. But when i enter a longer text into textview my edittext goes outside the table row. So it looks like it doesn't end. How can i fix it?
回答1:
just you set in TextView and EditText Views
android:layout_weight="1"
回答2:
Perhaps you can force the width to stay in the table using the formatter. You can read more about it here http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Formatter.html
来源:https://stackoverflow.com/questions/12622978/android-stop-edittext-from-going-outside-of-tablerow