大家好,我有问题。 我正在为TextView的背景使用gradientdrawable,如果文本视图没有多少行正在工作,但是如果有很多行我缺少背景,则TextView变得透明。 我在android 7上看到此问题,也可以在android 4.4.2上工作... 看屏幕截图,这是确切的情况。
该如何解决?由于角半径,我需要GradientDraweable。
这是测试应用程序的完整代码
public class MainActivity extends AppCompatActivity {
String testText1="a\n" +
"a\n" +
"a\n" +
"a\n" +
"a\n" +
"a\n" +
"a\n" +
"a";
String testText2="b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b\n" +
"b";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ScrollView root=new ScrollView(this);
TextView testWorking=new TextView(this);
testWorking.setTextColor(Color.BLACK);
testWorking.setTextSize(TypedValue.COMPLEX_UNIT_DIP,16);
testWorking.setText(testText1);
TextView testNotWorking=new TextView(this);
testNotWorking.setTextColor(Color.BLACK);
testNotWorking.setTextSize(TypedValue.COMPLEX_UNIT_DIP,16);
testNotWorking.setText(testText2);
GradientDrawable testBG=new GradientDrawable();
float chat_msgOut_each_corner_radi[] = {20f,20f, 20f,20f, 20f,20f, 20f,20f};
testBG.setCornerRadii(chat_msgOut_each_corner_radi);
testBG.setStroke(10, Color.TRANSPARENT);
testBG.setColor(Color.BLUE);
testWorking.setBackground(testBG);
testWorking.setGravity(Gravity.CENTER);
testNotWorking.setBackground(testBG);
testNotWorking.setGravity(Gravity.CENTER);
LinearLayout ll=new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
ll.addView(testWorking);
ll.addView(testNotWorking);
root.addView(ll);
setContentView(root);
}
谢谢。