我正在以编程方式添加editText控件,并且控件的值比控件的宽度长,并且正在换行到下一行。 我希望文本水平读取而不跨越多行或允许垂直滚动
我尝试了以下设置的多种组合,但它们似乎根本没有影响它。
et.setHorizontallyScrolling(true);
et.setSingleLine(true);
et.setLines(1);
et.setMaxLines(1);
et.setHorizontalScrollBarEnabled(true);
et.setRawInputType(InputType.TYPE_CLASS_TEXT| InputType.TYPE_TEXT_FLAG_IME_MULTI_LINE);
答案 0 :(得分:0)
只需在此
的帮助下更改您的代码.... public class MainActivity extends Activity {
private LinearLayout ll;
private ScrollView sv;
private EditText et,et1,et2,et3;
@Overrid
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
ll.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
et = new EditText(this);
et.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
et.setHeight(80);
sv = new ScrollView(this);
sv.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
sv.addView(et);
ll.addView(sv);
setContentView(ll);
}
}
答案 1 :(得分:0)
全部删除,仅使用et.setSingleLine(true);
答案 2 :(得分:0)
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
ll.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT));
EditText et = new EditText(this);
et.setSingleLine(true);
et.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT));
et.setRawInputType(InputType.TYPE_CLASS_TEXT| InputType.TYPE_TEXT_FLAG_IME_MULTI_LINE);
ll.addView(et);
setContentView(ll);
}
仅使用setSingleLine(true);
这样可以正常使用。