다음 구조의 abc.xml이 있습니다.Android : 중첩 된 레이아웃에 동적으로 뷰 추가
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/linear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
</LinearLayout>
</RelativeLayout>
</ScrollView>
선형 레이아웃에 동적으로 textviews를 추가하려고합니다. 아래는 제 코드입니다. 나는 어떤 오류도 내지 않지만 원하는 결과를 얻지 못하고있다. 당신의 XML은 텍스트 뷰를 추가
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
</LinearLayout>
</LinearLayout>
</ScrollView>
와 자바 코드해야
LayoutInflater Inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = Inflater.inflate(R.layout.abc, null);
LinearLayout layout = (LinearLayout) view.findViewById(R.id.linear);
TextView Tag = new TextView(getActivity());
Tag.setText("textString");
Tag.setBackgroundResource(R.color.bg_color);
Tag.setTextAppearance(getActivity(), R.style.SmallFont);
layout.addView(Tag);
왜 RelativeLayout을 사용하고 있습니까? –
나는 텍스트 뷰와 버튼 뷰와 같은 상대 레이아웃의 다른 뷰도 가지고 있습니다. – Shah