Android: запретить EditText выходить за пределы таблицы

Итак, у меня есть tablelayout в Android с некоторыми строками таблицы. В каждой строке у меня есть текстовое представление и текст редактирования. Моя установка выглядит так:

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

Все работает нормально. Но когда я ввожу более длинный текст в текстовое представление, мой текст редактирования выходит за пределы строки таблицы. Так что, похоже, это не конец. Как я могу это исправить?


person gabrjan    schedule 27.09.2012    source источник


Ответы (2)


просто вы установили в TextView и EditText Views

android:layout_weight="1"

person NagarjunaReddy    schedule 27.09.2012
comment
Таким образом, мой текстовый вид помещается в 2 строки. Я не выгляжу очень глупо. И если я добавлю android_singeline=true. Он делает строку похожей на myStrin... Он удаляет некоторые символы и добавляет... - person gabrjan; 27.09.2012
comment
Теперь я установил вес для textview на 0,001 и edittext на 1, и теперь он работает так, как должен! Спасибо! - person gabrjan; 27.09.2012

Возможно, вы можете заставить ширину оставаться в таблице с помощью средства форматирования. Подробнее об этом можно прочитать здесь http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Formatter.html

person calmond    schedule 27.09.2012