简体   繁体   English

Android EditText:如何摆脱图形故障?

[英]Android EditText: How do I get rid of the graphical glitches?

When I create an EditText in a standard-activity using the following setContentView with the following View: 当我使用以下setContentView和以下视图以标准活动创建EditText时:

public final class TestView extends LinearLayout {

    public TestView(Context context) {
        super(context);

        EditText text2 = new EditText(context);
        text2.setText("Test");
        this.addView(text2);
    }

}

I get graphical glitches like the following when editing it: 编辑时出现如下图形故障:

图形故障

How can I get rid of those? 我该如何摆脱这些? Is this an Android Bug? 这是Android Bug吗?

You haven't set any parameters to the EditText. 您尚未为EditText设置任何参数。 Try setting the parameters for it and check, 尝试为其设置参数并检查,

EditText text2 = new EditText(context);
        text2.setText("Test");      
        text2 .setLayoutParams(new LinearLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
                1f));
        text2 .setWidth(100);       
        text2 .setMaxLines(1);
        this.addView(text2);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM