【问题标题】:Android: Stop EditText from going outside of tablerowAndroid:阻止 EditText 离开 tablerow
【发布时间】:2012-09-27 13:50:37
【问题描述】:

所以我在 android 中有一个带有一些表格行的表格布局。在每一行中,我都有一个 textview 和一个 edittext。我的设置如下:

<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>

一切正常。但是,当我在 textview 中输入更长的文本时,我的 edittext 会超出表格行。所以看起来它并没有结束。我该如何解决?

【问题讨论】:

    标签: android textview android-edittext tablerow android-tablelayout


    【解决方案1】:

    只是你在 TextView 和 EditText 视图中设置的

    android:layout_weight="1"

    【讨论】:

    • 这样它将我的文本视图放在 2 行中。我看起来并不傻。如果我添加 android_singeline=true。它使字符串看起来像 myStrin...它删除了一些字符并添加...
    • 现在我将 textview 的权重设置为 0.001 并将 edittext 设置为 1,现在它应该可以正常工作了!谢谢你!
    【解决方案2】:

    也许您可以使用格式化程序强制宽​​度留在表格中。你可以在这里阅读更多关于它的信息http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Formatter.html

    【讨论】:

      猜你喜欢
      • 2013-08-23
      • 1970-01-01
      • 2012-07-16
      • 1970-01-01
      • 1970-01-01
      • 2011-09-19
      • 1970-01-01
      • 1970-01-01
      • 2012-08-08
      相关资源
      最近更新 更多