Android 如何在TableLayout中自动调整EditText小部件(具有某些属性)的大小
我有一个布局问题。我所做的是:Android 如何在TableLayout中自动调整EditText小部件(具有某些属性)的大小,android,resize,android-edittext,tablelayout,tablerow,Android,Resize,Android Edittext,Tablelayout,Tablerow,我有一个布局问题。我所做的是: 在xml中创建没有子项的TableLayout: 以编程方式在onCreate()中插入第一行: tablelayoutcontents=(TableLayout)findViewById(R.id.t_layout_contents) NoteElement nr_1=新的NoteElement(本) tLayoutContents.addView(nr_1) 类“NoteElement”扩展了TableRow。第一行只是由一个空白的图像视图(作为占位符)和一
tablelayoutcontents=(TableLayout)findViewById(R.id.t_layout_contents)
NoteElement nr_1=新的NoteElement(本)
tLayoutContents.addView(nr_1)代码>
public NoteElement(Context c) {
super(c);
this.context = c;
defaultText = c.getResources().getString(R.string.create_note_help_text);
imageView = new ImageView(context);
imageView.setImageResource(android.R.color.transparent);
LayoutParams params = new LayoutParams(0);
imageView.setLayoutParams(params);
addView(imageView);
addView(addTextField());
}
方法addTextField()指定EditText小部件的属性:
private EditText addTextField() {
editText = new EditText(context);
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
editText.setMinLines(4);
editText.setRawInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
editText.setHint(R.string.create_note_et_blank_text);
editText.setAutoLinkMask(Linkify.ALL);
editText.setPadding(5, 0, 0, 0);
editText.setGravity(Gravity.TOP);
editText.setVerticalScrollBarEnabled(true);
LayoutParams params = new LayoutParams(1);
editText.setLayoutParams(params);
return editText;
}
到目前为止,一切顺利。但我的问题是,一旦可用的空间耗尽,就出现了。EditText不会调整自身大小,但会切换为单行EditText。
我急切地寻找一种方法,EditText根据插入的文本长度动态调整其高度
有人对此有什么暗示吗 好的,我明白了。总的来说,这似乎是
TableLayout
的一个问题。我用一个简单的线性布局重新实现了布局。I同样适用于此目的,EditText
显示正确。事实上,我看不到使用表格布局的理由,现在我想不出一种实际需要它的情况,即线性布局是不够的。
因此,我建议尽可能使用其他布局,如LinearLayout
或RelativeLayout
。但请注意,这只是我的两分钱…我只是为了一个完全不同的目的再次查看了TableLayout,偶然发现了setColumnShrinkable(int-columnIndex,boolean-isShrinkable)
,这本应该对我以前的问题有所帮助
有关详细信息,请参阅文档:
请注意,我还没有测试过这个