如何使 Edittext 大小保持不变?安卓
我知道使 Edittext 左侧的文本“消失”以保持单行的属性(singleLine =“true”)。但我的问题是,当我在显示视图之前填充编辑文本时...在这种情况下,我的编辑文本都超出了屏幕... 有什么想法吗? 谢谢!
这是填充空的 Edittext 时得到的结果。一切都保持原样,左侧的文本消失
我从我的数据库中预填充
的代码:
<EditText android:id="@+id/InscripChampNom"
android:layout_height="wrap_content" android:textSize="14px"
android:inputType="textPersonName" android:layout_marginRight="20dip"
android:singleLine="true" android:textColor="@color/background"></EditText>
这里是edittext 定义如下:
<TableLayout android:layout_width="fill_parent"
android:stretchColumns="1" android:layout_height="fill_parent">
我也尝试过该属性
android:layout_width="fill_parent"
,但
android:layout_width="wrap_content"
根本没有成功...
也许输入类型和单行之间存在冲突?
编辑这里是我的问题的完整代码:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:scrollbars="vertical" android:background="@color/backgroundzen"
android:layout_gravity="fill" android:layout_height="fill_parent"
android:layout_width="fill_parent" android:paddingLeft="6dip"
android:paddingRight="6dip">
<TableLayout style="@style/LayoutWhiteBgrdFillWrap"
android:paddingLeft="6dip" android:paddingRight="6dip"
android:stretchColumns="1">
<TextView android:id="@+id/NomFormationConference" style="@style/textViewTitleRedzenBold"
android:text="Nom conférence"></TextView>
<TableRow android:layout_margin="2dip">
<TextView android:id="@+id/DateSession" android:textColor="@color/textezenrouge"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:text="date début"></TextView>
<TextView android:id="@+id/speakerConf" android:textColor="@color/textezenrouge"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:text="speaker"></TextView>
</TableRow>
<TableRow android:layout_margin="2dip">
<TextView android:id="@+id/InscripNom" android:layout_width="wrap_content"
android:textColor="@color/background" android:layout_height="wrap_content"
android:text="@string/nom" android:textStyle="bold"></TextView>
<EditText android:id="@+id/InscripChampNom"
android:layout_height="wrap_content" android:textSize="14sp"
android:layout_width="fill_parent" android:inputType="textPersonName"
android:layout_marginRight="20dip" android:hint="@string/nomh"
android:singleLine="true" android:textColor="@color/background"></EditText>
</TableRow>
//最后一个表行重复 5 次,其中包含各种数据。
样式是这样的:
<style name="LayoutWhiteBgrdFillWrap">
<item name="android:background">@color/backgroundzen</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
</style>
这是我填充 EditText
的方式:
misc = SQLiteDatabase.openDatabase("/data/data/com.mobile.zen/databases/" + Constants.UNVERSIONNED_DATABASE, null,
SQLiteDatabase.OPEN_READONLY);
Cursor c = misc.query("MISC", null, null, null, null, null, null);
if (c.moveToFirst()) {
do {
nomInscrit.setText(c.getString(1));
} while (c.moveToNext());
}
c.close();
misc.close();
I know the attribute which makes the text "disapear" on the left part of the Edittext to maintain a single line, (singleLine="true"). But my issue is when I fill the edittext before the view is displayed... in this case, my edittexts are all going out of the screen...
any ideas?
thx!
This is what is get when fill the empty Edittext. Everything stays put, and the text is vanishing on its left side
and when I prefill from my DB
here is the code of the edittext :
<EditText android:id="@+id/InscripChampNom"
android:layout_height="wrap_content" android:textSize="14px"
android:inputType="textPersonName" android:layout_marginRight="20dip"
android:singleLine="true" android:textColor="@color/background"></EditText>
The tableLayout is defined as follows:
<TableLayout android:layout_width="fill_parent"
android:stretchColumns="1" android:layout_height="fill_parent">
I also tried with the attribute
android:layout_width="fill_parent"
and
android:layout_width="wrap_content"
no success at all...
Maybe there is a conflict between input type and singleline?
EDIT Here is the full code of my issue :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:scrollbars="vertical" android:background="@color/backgroundzen"
android:layout_gravity="fill" android:layout_height="fill_parent"
android:layout_width="fill_parent" android:paddingLeft="6dip"
android:paddingRight="6dip">
<TableLayout style="@style/LayoutWhiteBgrdFillWrap"
android:paddingLeft="6dip" android:paddingRight="6dip"
android:stretchColumns="1">
<TextView android:id="@+id/NomFormationConference" style="@style/textViewTitleRedzenBold"
android:text="Nom conférence"></TextView>
<TableRow android:layout_margin="2dip">
<TextView android:id="@+id/DateSession" android:textColor="@color/textezenrouge"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:text="date début"></TextView>
<TextView android:id="@+id/speakerConf" android:textColor="@color/textezenrouge"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:text="speaker"></TextView>
</TableRow>
<TableRow android:layout_margin="2dip">
<TextView android:id="@+id/InscripNom" android:layout_width="wrap_content"
android:textColor="@color/background" android:layout_height="wrap_content"
android:text="@string/nom" android:textStyle="bold"></TextView>
<EditText android:id="@+id/InscripChampNom"
android:layout_height="wrap_content" android:textSize="14sp"
android:layout_width="fill_parent" android:inputType="textPersonName"
android:layout_marginRight="20dip" android:hint="@string/nomh"
android:singleLine="true" android:textColor="@color/background"></EditText>
</TableRow>
//The last tablerow is repeated 5 times with various data inside.
The style is like that :
<style name="LayoutWhiteBgrdFillWrap">
<item name="android:background">@color/backgroundzen</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
</style>
And here is how I fill the EditText
:
misc = SQLiteDatabase.openDatabase("/data/data/com.mobile.zen/databases/" + Constants.UNVERSIONNED_DATABASE, null,
SQLiteDatabase.OPEN_READONLY);
Cursor c = misc.query("MISC", null, null, null, null, null, null);
if (c.moveToFirst()) {
do {
nomInscrit.setText(c.getString(1));
} while (c.moveToNext());
}
c.close();
misc.close();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
尝试将
android:shrinkColumns="1"
添加到您的TableLayout
中,告诉它它可以强制EditText
项目变小以适应屏幕的宽度。Try adding
android:shrinkColumns="1"
to yourTableLayout
to tell it that it can force theEditText
items to be smaller to fit into the width of the screen.您的
EditText
上没有android:layout_width
属性。添加一个或以其他方式限制字段的长度(例如,如果它位于RelativeLayout
中,则使用android:layout_alignParentRight="true"
)。You have no
android:layout_width
attribute on yourEditText
. Add one or otherwise constrain how long the field can be (e.g., if it is in aRelativeLayout
, useandroid:layout_alignParentRight="true"
).我只是试图重现您的问题,但我做不到。
检查一下:
I just tried to reproduce your issue but I couldn't.
Check this:
可能是 Android 中的一个可能的错误。但解决此问题的一种方法可能是指定某个值作为编辑文本框的宽度并指定
我还为 TableRow 添加了高度和宽度属性
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
I have also Added height and width property for TableRow
我认为 tablelayout 在滚动视图中不起作用。
我有这样的设置,它不会抛出错误
但模拟器只是不加载应用程序并说停止工作。
我删除了滚动视图,事情开始工作。
我认为问题是表格布局有自己的滚动条
它不需要滚动视图,也许两者冲突。
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.