これはうまくいくわけではありませんが、ヒントを得ることを期待しています。私の研究ではコードがうまくいくはずです。 。既存のlayout.xmlにLinearLayoutにテキストビューを追加したい場合は
私が含まれ、既存のlayout.xmlのファイルがあります:アクティビティがディあるときに新しいのTextViewが表示されない
LinearLayout ll = new LinearLayout(this);
ll = (LinearLayout)findViewById(R.id.scrollLinearLayout);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
TextView tv = new TextView(this);
tv.setId(1);
tv.setTextSize(R.dimen.text_size_medium);
tv.setText("test");
tv.setLayoutParams(lp);
ll.addView(tv);
:
<RelativeLayout style="@style/bodyLayout">
<ScrollView
android:id="@+id/scrollBody"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="false"
>
<LinearLayout
android:id="@+id/scrollLinearLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</LinearLayout>
</ScrollView>
</RelativeLayout>
を次のようにその後、私はプログラムによるコードを持っているが広がった、私はあなたが新しいビュー(何を)追加した場合、私はあなたのコードが
LinearLayout ll = (LinearLayout)findViewById(R.id.subLinear);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
TextView tv = new TextView(this);
tv.setId(1);
tv.setTextSize(15);
tv.setText("test adding");
tv.setLayoutParams(lp);
ll.addView(tv);
正常に動作し実行した
このリンクはあなたを助けることができる、それがリフレッシュされます
この行を追加します。 flow.com/questions/4203506/how-can-i-add-a-textview-to-a-linearlayout-dynamically-in-android/27781046#27781046 –