如何动态添加此类布局 (android)

How to add this type of layout dynamically (android)

我有一种格式,它会重复,只有其中 image/the 文本的内容会动态变化。 此格式将根据网络结果动态添加

线性布局 { 线性布局 { 线性布局 {图片+文字} 线性布局 {图片+文字} 线性布局 {图片+文字+图片+文字+图片+文字} } }

创建一个包含您的格式的布局。并声明一个将保存您的动态视图的布局。使用 Layout inflater,您可以根据需要添加许多视图。

 LinearLayout ll = (LinearLayout) findViewById(R.id.parent);

    for(int i=0;i<result.length();i++){
    LayoutInflater inflater = (LayoutInflater) getSystemService( Context.LAYOUT_INFLATER_SERVICE );
    View format = inflater.inflate(R.layout.format, null);

    ll.addView(format);
}