Android Linearlayout中动态添加ImageView
2016-08-01 10:44
609 查看
需求:界面有时候显示图片的数量未知,需要在代码中动态添加图片。
方法步骤:
1.布局:
2.代码:
方法步骤:
1.布局:
<LinearLayout android:id="@+id/ll_group" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_centerHorizontal="true"> </LinearLayout>
2.代码:
LinearLayout llGroup = (LinearLayout) findViewById(R.id.ll_group); //size:代码中获取到的图片数量 private void addGroupImage(int size){ llGroup.removeAllViews(); //clear linearlayout for (int i = 0; i < size; i++) { ImageView imageView = new ImageView(this); imageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); //设置图片宽高 imageView.setImageResource(R.drawable.ic_launcher); //图片资源 llWindLayout.addView(imageView); //动态添加图片 } }
相关文章推荐
- Android中利用LinearLayout动态添加控件
- android LinearLayout 动态添加子View
- Android中利用LinearLayout动态添加控件
- Android中利用LinearLayout动态添加控件
- android动态加载控件(LinearLayout)并获取动态添加的EditText里的值
- Android中利用LinearLayout动态添加控件
- Android中利用LinearLayout动态添加UI控件
- Android 搜索页-搜索历史条目动态添加(LinearLayout动态添加条目)
- Android中利用LinearLayout动态添加控件
- android LinearLayout 单击动态改变背景
- android 动态添加组件,layout的宽高的正确显示
- android LinearLayout添加分隔线
- android动态添加TextView或者ImageView
- 给android的LinearLayout添加点击事件
- android LinearLayout容器添加分割线
- 给Android的LinearLayout添加点击事件
- android LinearLayout 单击动态改变背景
- android ListView item里动态增加多个LinearLayout的问题
- android 给LinearLayout中添加一定数量的控件,并让着一定数量的控件从右到左移动,每隔若干秒停顿一下,最后一个view链接第一个view,然后继续移动循环往复,形成一个死循环简单动画效果
- android动态布局:用java代码实现LinearLayout以及TextView