简体   繁体   English

Android:阻止EditText移到表行之外

[英]Android: Stop EditText from going outside of tablerow

So i have a tablelayout in android with some table rows. 所以我在Android中有一些表行的tablelayout。 In each row i have a textview and an edittext. 在每一行中,我都有一个textview和一个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. 但是,当我在textview中输入较长的文本时,我的edittext不在表格行中。 So it looks like it doesn't end. 因此,看起来它并没有结束。 How can i fix it? 我该如何解决?

只要您在TextView和EditText视图中进行设置

android:layout_weight="1"

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 您可以在这里阅读更多有关它的信息http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Formatter.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM