2011-09-21 58 views
-2

这是来自Activity文件的代码。我希望布局看起来相同,但我希望XML格式的代码。因为动态地使用一些代码并且在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); 

} 
+0

所以ü希望我们的代码ü? – the100rabh

+0

如果你或某人能够给我一些关于如何使这个过程的提示,我会非常感谢。 –

+0

@Patrik http://developer.android.com/guide/topics/ui/declaring-layout.html – slayton

回答

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