如何在android中以编程方式更改编辑文本的位置? [英] How to change the position of edit text programmatically in android?
问题描述
我使用RelativeLayout以编程方式创建了许多编辑文本。每个编辑文本的默认宽度为wrap_content,但是当编辑文本到达屏幕边缘时,它会直观地更改其大小。那么当这种情况发生时如何让它移动到下一行?
I'm creating a number of edit texts next to each other programmatically using RelativeLayout. The default width of each edit text is wrap_content, but when the edit text reaches the edge of the screen, it visually changes it's sizes. So how can I make it move to the next line when this happens?
private EditText createEditText(EditText editText1, EditText editText2, String word){
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
editText.getLayoutParams().width,
editText.getLayoutParams().height
);
layoutParams.addRule(RelativeLayout.RIGHT_OF, editText1.getId());
layoutParams.addRule(RelativeLayout.BELOW, textView.getId());
layoutParams.leftMargin += 60;
editText2.setHint("" + word);
editText2.setHintTextColor(editText.getSolidColor());
editText2.setBackgroundResource(R.drawable.rounded_edittext);
editText2.setLayoutParams(layoutParams);
editText2.setPadding(editText.getPaddingLeft(), editText.getPaddingTop(), editText.getPaddingRight(), editText.getPaddingBottom());
editText2.setId(View.generateViewId());
relativeLayout.addView(editText2);
return editText2;
}
推荐答案
在android和dynamiaclly中尝试FlowLayout在其中填充TextView。
Try FlowLayout in android and dynamiaclly inflate TextViews in it.
除此之外,您可以在每行中使用具有固定数量子项的Linearlayout,如果这样做,则子项必须具有相同的layout_weight。
Rather than that you can use Linearlayout with fixed number of children in each row and if doing this the children must having same layout_weight.
但是,我会要求您在android
But rather than going in such big disputes i will request you to simply replace RelativeLayout With FlowLayout in android
这篇关于如何在android中以编程方式更改编辑文本的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!