[英]How to change the position of edit text programmatically in android?
我正在使用RelativeLayout以編程方式彼此相鄰創建許多編輯文本。 每個編輯文本的默認寬度為wrap_content,但是當編輯文本到達屏幕邊緣時,它會在視覺上更改其大小。 那么發生這種情況時,如何使它移到下一行?
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中使用FlowLayout,然后動態地在其中填充TextViews。
與其相反,您可以在每行中使用固定數量的子代使用Linearlayout,並且如果這樣做,則子代必須具有相同的layout_weight。
但是,我不會要求您在Android中將FlowForm替換為RelativeLayout
您可以嘗試的。 不確定,是否可以。 您可以做的是在onCreate上計算屏幕的寬度,並檢查視圖是否超過該寬度,在最后一個視圖下方創建一個新的相對視圖。 老實說,線性布局將更容易使用weight屬性進行維護。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.