私は以下の構造の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を動的に追加したいとします。以下は私のコードです。私は間違いはありませんが、私は望みの結果を得ていません。
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を使用していますか? –
私は相対レイアウトで他のビューを持っているだけでなく、textviewsとbuttonviews – Shah