我的TextViews具有正方形背景,数字每秒出现一次。我使用方形图像作为背景,并将文本重心设置为将正方形中的数字居中。它在xxhdpi手机上不起作用。我怎样才能让数字居中?TextView的中心重力无法在RelativeLayout中的xxhdpi上工作
这是代码:
displayingCell = new TextView(MyActivity.this);
displayingCell.setTypeface(null, Typeface.BOLD);
displayingCell.setTextSize(mySize);
displayingCell.setTextColor(Color.BLACK);
displayingCell.setGravity(Gravity.CENTER);
displayingLayoutParam = new RelativeLayout.LayoutParams(diameter, diameter);
displayingLayoutParam.setMargins(marginLeft, marginTop, 0, 0);
displayingCell.setLayoutParams(displayingLayoutParam);
displayingCell.setBackground(myImage);
displayingCell.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
你能张贴您的布局XML? – Prexx
我以编程方式添加单元格。 –
如果您正在使用重力中心,则不应使用添加边距,这是没有意义的。 –