I am adding an editText control programmatically and the value of the control is longer than the width of the control and is wrapping onto the next line. I want the text to read horizontally instead and not span multiple lines or allow vertical scrolling
I have tried multiple combinations of the following settings but they don't seem to affect it at all.
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);
Just Change Your code ....with the help of this
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);
}
}
全部删除,仅使用et.setSingleLine(true);
@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);
}
Use only setSingleLine(true);
this works fine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.