私のlayout.xml
ファイルは次のようになります。
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="270dp"
android:layout_weight="0.47" >
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
次のコードを使用して、ループ内にTextView
sとsを作成します。Button
for
View linearLayout = findViewById(R.id.linearLayout2);
for (int i=0 ; i<10; i++){
TextView textview = new TextView(this);
textview.setText("Text view" + i);
textview.setId(i);
textview.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
((LinearLayout) linearLayout).addView(textview);
Button button = new Button(this);
button.setText("View");
button.setId(i);
int width=90;
int height=60;
button.setLayoutParams(new LayoutParams(width, height));
((LinearLayout) linearLayout).addView(button);
}
Button
以下のTextViewを取得しています。LinearLayout
誰かがこれを置き換えて、とを並べてRelativeLayout
取得するのを手伝ってもらえますか?TextView
Button