当前位置:   article > 正文

android 动态addview注意_android addview framelayout

android addview framelayout

以前用的这种方式:

inflate布局

        filterLayout = (FrameLayout) inflater.inflate(R.layout.camera_photo_filter, null);

然后再:

创建params

        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, activity
                .getResources().getDimensionPixelSize(R.dimen.bottom_bar_height_optimal));
       params.gravity = Gravity.BOTTOM;

添加view:

        mModeListView.addView(filterLayout,params);

然后觉得很奇怪,为啥我在xml中写了 paramas,还要 new params 呢?


于是抱着试试看的态度

        filterLayout = (FrameLayout) inflater.inflate(R.layout.camera_photo_filter, null) 

        mModeListView.addView(filterLayout);

发现params没有生效




最后解决方法:

   filterLayout = (FrameLayout) inflater.inflate(R.layout.camera_photo_filter, mModeListView);

一句话就好了

害我搞半天



声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/225309
推荐阅读
相关标签
  

闽ICP备14008679号