1

我尝试按屏幕尺寸制作文本之间的边距。

除了一个 TextView 之外,它运行良好。

只有mon右边距不起作用。

感谢您的帮助:)

这是代码和图片:

public void setDaysBar()
    {

    Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();

    if (android.os.Build.VERSION.SDK_INT >= 13)
      {
          Point size = new Point();
          display.getSize(size);
          width = size.x;
      }
      else
          width = display.getHeight();  

    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);        
    lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    sun.setLayoutParams(lp);

    lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);        
    lp.addRule(RelativeLayout.RIGHT_OF, R.id.textView3);        
    lp.setMargins(0, 0, width/6, 0);
    mon.setLayoutParams(lp);

    lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);        
    lp.addRule(RelativeLayout.RIGHT_OF, R.id.textView2);
    lp.setMargins(0, 0, width/6, 0);
    tue.setLayoutParams(lp);

    lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);        
    lp.addRule(RelativeLayout.RIGHT_OF, R.id.textView9);
    lp.setMargins(0, 0, width/6, 0);
    wed.setLayoutParams(lp);

    lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);        
    lp.addRule(RelativeLayout.RIGHT_OF, R.id.textView1);
    lp.setMargins(0, 0, width/6, 0);
    thu.setLayoutParams(lp);

    lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);        
    lp.addRule(RelativeLayout.RIGHT_OF, R.id.textView4);
    lp.setMargins(0, 0, width/6, 0);
    fri.setLayoutParams(lp);

    lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
    lp.addRule(RelativeLayout.RIGHT_OF, R.id.textView6);
    lp.setMargins(0, 0, width/6, 0);
    sat.setLayoutParams(lp);

    }

在此处输入图像描述

4

1 回答 1

1

我认为你也应该setMargins()在星期天 - 看起来你已经忘记了它。
如果你这样做,一切都应该很好。

RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);        
lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
lp.setMargins(0, 0, width / 6, 0);
sun.setLayoutParams(lp);
于 2013-06-23T23:54:42.450 回答