中心的EditText水平线

时间:2012-10-10 09:36:38

标签: android layout

EditText上有一条灰色线在On android 4.0.4(Galaxy S3)你可以看到: https://www.dropbox.com/s/c4xz2yjaw1fbamr/Screenshot_2012-10-10-11-59-29.png 您可以在以下位置看到Galaxy S(Android 2.3.3)没有问题: https://www.dropbox.com/s/1l6a7u9f8ey7q76/device-2012-10-10-120640.png

我使用以下代码创建它们。我对XML文件没有做任何事情。它可能有什么问题?

由于

        for (int i = 0; i < editTexts.length; i++) {

            EditText rowEditText = new EditText(getBaseContext());

            rowEditText.setSingleLine(true);
            rowEditText.setTextColor(Color.BLACK);
            rowEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT);
            filters[0] = new InputFilter.LengthFilter(10);
            rowEditText.setFilters(filters);    
            rowEditText.setHint((i + 1) + ".Oyuncu"); 

            LinearLayout.LayoutParams layoutParams=new LinearLayout.LayoutParams((int) (metrics.widthPixels * (0.6f)), (int) (metrics.heightPixels * (0.07f)));
            spinnerlayout.addView(rowEditText,layoutParams);
            editTexts[i] = rowEditText;


        }

1 个答案:

答案 0 :(得分:0)

我发现了问题。 代码是这样的:

      EditText rowEditText = new EditText(getBaseContext());

我改为:

      EditText rowEditText = new EditText(Class.this);

获得的经验教训:不要在活动中使用getBaseContext()或getApplicationContext()