美文网首页
动态添加view 设置view之间的间隔

动态添加view 设置view之间的间隔

作者: Lost_Robot | 来源:发表于2017-09-27 10:07 被阅读223次

在写一个应用商城的APP,有一个页面需要显示APP的详细信息,有多个APP截图需要显示:
如:

详细信息页面

这个时候就需要动态添加ImageView在布局中,需要设置每一个ImageView的间距
1.设置布局文件xml包含一个线性布局:

线性布局

代码实现:

//初始化
 app_Show = findViewById(R.id.app_info_showpic) as LinearLayout
//设置子视图的布局
  val ll = LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)
        ll.setMargins(0, 10, 0, 10)

        for (str in data) {
            val iv = ImageView(this)  //子视图
            iv.layoutParams = ll  //设置子视图的布局
            x.image().bind(iv, str, imageOptions) //初始化子视图的数据
            app_Show?.addView(iv)  //添加子视图

        }

运行结果:

运行结果展示

相关文章

网友评论

      本文标题:动态添加view 设置view之间的间隔

      本文链接:https://www.haomeiwen.com/subject/afbyextx.html