TextView的中心重力不适用于RelativeLayout中的xxhdpi

时间:2017-05-29 12:11:16

标签: java android

我有带有方形背景的TextViews,每秒都会显示数字。我使用方形图像作为背景,并将文本重心设置为正方形中的数字居中。它不适用于xxhdpi手机。我如何将这些数字集中在一起?

enter image description here

这是代码:

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);

2 个答案:

答案 0 :(得分:1)

尝试删除

Count_group

并添加

    ID  Day   Count Count_group
    18  1933    6   11
    33  1933    6   11
    37  1933    6   11
    18  1933    6   11
    16  1933    6   11
    11  1933    6   11
    111 1932    5   11
    34  1932    5   11
    60  1932    5   11
    88  1932    5   11
    18  1932    5   11
    111 1932    5   8
    34  1932    5   8
    60  1932    5   8
    88  1932    5   8
    18  1932    5   8
    33  1931    3   8
    13  1931    3   8
    56  1931    3   8
    33  1931    3   4
    13  1931    3   4
    56  1931    3   4
    23  1930    1   4
    23  1930    1   1
    6   1800    6   10
    37  1800    6   10
    98  1800    6   10
    52  1800    6   10
    18  1800    6   10
    76  1800    6   10
    55  1799    4   10
    6   1799    4   10
    52  1799    4   10
    133 1799    4   10
    55  1799    4   6
    6   1799    4   6
    52  1799    4   6
    133 1799    4   6
    112 1798    2   6
    677 1798    2   6
    112 1798    2   2
    677 1798    2   2
    778 888     4   6
    111 888     4   6
    88  888     4   6
    10  888     4   6
    37  887     2   6
    26  887     2   6
    37  887     2   3
    26  887     2   3
    8   886     1   3
    8   886     1   2
    56  885     1   2
    56  885     1   1

答案 1 :(得分:0)

如果此问题仅出现在xxhdpi设备上,那么您可以检查设备的运行时间并将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;
        }