我有一个结构如下的abc.xml文件。
<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>
我想在线性布局中动态添加文本视图。以下是我的代码。我没有收到任何错误,但我没有得到期望的结果。
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);