RelativeLayout.LayoutParams addRule()不起作用

时间:2016-07-05 11:08:21

标签: java android android-layout relativelayout

我试图将每个新标签放在彼此之下。每个ID都会在添加到屏幕时获取新ID,并且如果标签不是第一个(idnumer != 0),则它们位于前一个标签下方(第一个标签添加到顶部)。然而,它们并不是正确的,而是在顶部相互重叠。我做错了什么?

while ((line = reader2.readLine()) != null) {
    TextView mTextv = new TextView(getApplicationContext());
    mTextv.setText(line);
    RelativeLayout linearLayout = (RelativeLayout) findViewById(R.id.rlX);
    mTextv.setTextSize(20);
    mTextv.setId(idnumber);
    RelativeLayout.LayoutParams paramsX = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
    paramsX.setMargins(15,15,15,5);
    if(idnumber != 0) {                 
        paramsX.addRule(RelativeLayout.BELOW, findViewById(idnumber - 1).getId());
    }
    mTextv.setLayoutParams(paramsX);
    idnumber += 1;
    mTextv.setTypeface(Typeface.SANS_SERIF);
    mTextv.setTextColor(Color.parseColor("#009500"));
    linearLayout.addView(mTextv);
    scrollerF.invalidate();
}

0 个答案:

没有答案