1

我试图从 textViews 中列出列表。它就像我想要的那样工作,除了出于某种原因 i=0 和 i=1 都写在同一个地方。所以我的问题只是关于他们的立场。我不明白为什么 i=1 不低于 i=0。别人看到了吗?

public class See extends Activity {
RelativeLayout rl;
List<TextView>listFR  = new ArrayList<TextView>();
List<TextView>listDE  = new ArrayList<TextView>();
List<RelativeLayout.LayoutParams> FRParams = new ArrayList<RelativeLayout.LayoutParams>();
List<RelativeLayout.LayoutParams> DEParams = new ArrayList<RelativeLayout.LayoutParams>();



@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_see);
    Tree t = new Tree("T1");
    rl = (RelativeLayout)findViewById(R.id.rLayout);




    for(int i = 0;i<t.getSize();i++){

        FRParams.add(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        DEParams.add(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        FRParams.get(i).addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        DEParams.get(i).addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        if(i!=0){

        FRParams.get(i).addRule(RelativeLayout.BELOW, listFR.get(i - 1).getId());
        DEParams.get(i).addRule(RelativeLayout.BELOW, listDE.get(i - 1).getId()); 

        } else {

            FRParams.get(i).addRule(RelativeLayout.ALIGN_PARENT_TOP);
            DEParams.get(i).addRule(RelativeLayout.ALIGN_PARENT_TOP);
        }

        listFR.add(new TextView(See.this));
        listDE.add(new TextView(See.this));     
        listFR.get(i).setTextAppearance(See.this, android.R.style.TextAppearance_DeviceDefault);
        listDE.get(i).setTextAppearance(See.this, android.R.style.TextAppearance_DeviceDefault);
        listFR.get(i).setText(t.getLeaf(i).getFR());
        listDE.get(i).setText(t.getLeaf(i).getDE());
        listFR.get(i).setId(i);
        listDE.get(i).setId(i); 

        rl.addView(listFR.get(i), FRParams.get(i));
        rl.addView(listDE.get(i), DEParams.get(i)); 

    } 

}

}

4

0 回答 0