2 sachinks SachinKS 于 2013.06.24 17:15 提问

Android应用中setMargin不正常运行

如图所示:

CSDN移动问答

下面的代码实现了其它正常运行,但是只有星期一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);

    }

1个回答

Jave_
Jave_   2013.06.24 17:29

R.id.textView3
这个id是sun的id吗

glee_java
glee_java 學習中。。。
4 年多之前 回复
Jave_
Jave_ 改成sun的就可以了应该
4 年多之前 回复
SachinKS
SachinKS 不是,是Mon的
4 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!