2011-09-21 36 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>