当前位置:   article > 正文

Android开发FrameLayout动态添加控件位置问题_android framelayout添加子view到底部

android framelayout添加子view到底部

       首先FrameLayout的子控件默认都是从左上角显示的,还有最后添加的在最前面显示。

        一般是对FrameLayout.LayoutParams params进行操作,刚开始一直params.rightMargin来定位置,访了第一条准则,那就换种思路来做,比如params.leftMargin

        第二个重要的点:params需要每次生成一个新的,否则它以之后改变的为准的

示例代码:

  1. for(int i = 0;i < openBean.getList().size();i++){
  2. //需要每次new Params,防止用的都是最后一个的设置
  3. FrameLayout.LayoutParams headParams = new FrameLayout.LayoutParams(Utils.dip2px(mContext,40),Utils.dip2px(mContext,40));
  4. View headGroupView = UIUtils.inflate(mContext,R.layout.circle_head_layout);
  5. RelativeLayout rlHead = (RelativeLayout)headGroupView.findViewById(R.id.rl_circle_head);
  6. ImageView headImage = (ImageView)headGroupView.findViewById(R.id.iv_head_small);
  7. headParams.setMargins(i*Utils.dip2px(mContext,30),0,0,0);
  8. headGroupView.setLayoutParams(headParams);
  9. ImageLoaderUtil.loadCircular(headImage, openBean.getList().get(i).getHead_img(), mContext);
  10. holder1.fl_recommend_open_user.addView(headGroupView);
  11. }

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/225265
推荐阅读
相关标签
  

闽ICP备14008679号