How to make Edittext size stay put? Android

北战南征 提交于 2019-12-06 00:50:02

Try adding android:shrinkColumns="1" to your TableLayout to tell it that it can force the EditText items to be smaller to fit into the width of the screen.

You have no android:layout_width attribute on your EditText. Add one or otherwise constrain how long the field can be (e.g., if it is in a RelativeLayout, use android:layout_alignParentRight="true").

I just tried to reproduce your issue but I couldn't.

Check this:

<?xml version="1.0" encoding="utf-8"?>

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:stretchColumns="1"
    android:layout_height="fill_parent">

    <EditText android:id="@+id/a" android:layout_height="wrap_content"
        android:textSize="14px" android:inputType="textPersonName"
        android:layout_marginRight="20dip" android:singleLine="true"
        android:textColor="@android:color/black"></EditText>

    <EditText android:id="@+id/b" android:layout_height="wrap_content"
        android:textSize="14px" android:inputType="textPersonName"
        android:layout_marginRight="20dip" android:singleLine="true"
        android:textColor="@android:color/black"></EditText>

    <EditText android:id="@+id/c" android:layout_height="wrap_content"
        android:textSize="14px" android:inputType="textPersonName"
        android:layout_marginRight="20dip" android:singleLine="true"
        android:textColor="@android:color/black"></EditText>

</TableLayout>

Might be a possible bug in Android. But one way to solve it may be is to specify some value as a width to the Edit Text box and specify

android:stretchColumns="1"

   <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:scrollbars="vertical" android:background="#ffffff"
android:layout_gravity="fill" android:layout_height="fill_parent"
android:layout_width="fill_parent" android:paddingLeft="6dip">
  <TableLayout android:layout_below="@+id/reltable1" android:id="@+id/tablelayout_main" android:layout_width="fill_parent" android:layout_marginRight="10dip" android:layout_marginBottom="10dip" android:layout_height="fill_parent" android:layout_centerInParent="true" android:gravity="center" android:stretchColumns="1">
    <TextView android:id="@+id/NomFormationConference" 
        android:text="Nom conférence"></TextView>
    <TableRow android:layout_height="wrap_content" android:layout_width="fill_parent">
        <TextView android:id="@+id/DateSession"
            android:layout_height="wrap_content" android:layout_width="wrap_content"
            android:text="date début"></TextView>
        <TextView android:id="@+id/speakerConf" 
            android:layout_height="wrap_content" android:layout_width="wrap_content"
            android:text="speaker"></TextView>
    </TableRow>
      <TableRow android:layout_height="wrap_content" android:layout_width="fill_parent">
        <TextView android:id="@+id/InscripNom" android:layout_width="wrap_content"
           android:layout_height="wrap_content"
            android:text="nom" android:textStyle="bold"></TextView>
        <EditText android:id="@+id/InscripChampNom"
            android:textSize="14sp"
            android:inputType="textPersonName"
            android:hint="nomh" android:text="dsfdsfdsfsdfsdfsssssssssssssssssssssssssssssss" android:layout_height="wrap_content" android:fitsSystemWindows="true" android:layout_width="220dip" android:ellipsize="end"></EditText>
    </TableRow>
</TableLayout>
</ScrollView>

I have also Added height and width property for TableRow

i don't think tablelayout works in scrollview. i had a setup as such and it does not throw errors but the emulator just does not load the app and says stopped working. i removed the scrollview and thing started working.

i think the problem is that tablelayout has its own scroll bars it does not need scrollview and perhaps the two conflict.

cobain
<EditText 
    android:id="@+id/InscripChampNom"
    android:layout_height="wrap_content" 
    android:textSize="14px" 
    android:inputType="none" 
    android:layout_marginRight="20dip" 
    android:singleLine="true" 
    android:textColor="@color/background" 
    android:editable="false"
    android:ellipsize="end">
</EditText>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!