我创建了一个简单的 UI 并由 id mainContainer2 设置。我想知道这样的事情是否可以在循环中重用它,例如
<LinearLayout
android:id="@+id/mainContainer2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="@drawable/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
LinearLayout mainContainer = new LinearLayout(this);
mainContainer.setOrientation(LinearLayout.VERTICAL);
TextView textoqualquer = new TextView(this);
textoqualquer.setText("textoqualquer");
mainContainer.addView(textoqualquer);
LinearLayout maincontainer = new LinearLayout(this);
maincontainer.setOrientation(LinearLayout.VERTICAL);
maincontainer.findViewById(R.id.mainContainer2);
mainContainer.addView(maincontainer);
setContentView(mainContainer);