나는이 코드를 작동시킬 수 없다. 몇 가지 힌트를 얻고 싶다. 내 연구에서 코드가 작동해야한다고 생각한다. . 기존 layout.xml의 LinearLayout에 Textviews를 추가하고 싶습니다.
I이 포함 된 기존 layout.xml 파일을 다음과 같이<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 = 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);
새로운 텍스트 뷰가 표시되지 않습니다 디 벌리고, 나는
그것을 구성 요소를 새로 고쳐집니다 flow.com/questions/4203506/how-can-i-add-a-textview-to-a-linearlayout-dynamically-in-android/27781046#27781046 –