![](/img/trans.png)
[英]When RelativeLayout is into a ScrollView, moving TextView with touch doesn't work correctly
[英]Center Gravity for TextView doesn't work on xxhdpi in RelativeLayout
我有方形背景的TextViews,其数字每秒出现一次。 我使用正方形图像作为背景,并将文本重心设置为使数字居中。 在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);
尝试删除
displayingLayoutParam.setMargins
并添加
displayingLayoutParam.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
如果此问题仅出现在xxhdpi设备上,则可以检查设备的运行时并将marginbottom
设置为marginbottom
文本。 我在我的工具栏文本中添加了边距。 希望你能得到这个把戏
switch (getResources().getDisplayMetrics().densityDpi) {
case DisplayMetrics.DENSITY_HIGH:
Log.d("density:", "high");
toolbar.setTitleMarginStart(160);
break;
case DisplayMetrics.DENSITY_XHIGH:
// ...
Log.d("density:", "xhigh");
toolbar.setTitleMarginStart(200);
break;
case DisplayMetrics.DENSITY_XXHIGH:
Log.d("density:", "xxhigh");
toolbar.setTitleMarginStart(380);
break;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.