我如何将其转换为XML布局格式?

时间:2011-09-21 16:53:17

标签: java android xcode eclipse layout

这是来自Activity文件的代码。我想布局看起来一样,但我想要XML格式的代码。因为动态地使用一些代码并且在XML文件中有一些代码是非常令人不安的。那么有人可以从动态到xml布局吗?

    protected void initLayout() {

    // root view - GRN
    LinearLayout rootView = new LinearLayout(this.getApplicationContext());
    rootView.setOrientation(LinearLayout.VERTICAL);

    this.mText = new TextView(this.getApplicationContext());
    this.mText.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));
    rootView.addView(this.mText);

    this.eventLayout = new LinearLayout(this.getApplicationContext());
    this.eventLayout.setOrientation(LinearLayout.VERTICAL);
    ScrollView sv_obj = new ScrollView(this.getApplicationContext());
    sv_obj.addView(this.eventLayout);
    rootView.addView(sv_obj);
    this.setContentView(rootView);

}

1 个答案:

答案 0 :(得分:0)

<LinearLayout android:orientation="vertical>
    <TextView android:width="wrap_content  android:height="wrap_content/>
    <ScrollView>
        <LinerLayout android:orientation="vertical> 
        </LinearLayout>
    </ScrollView>
</LinearLayout>