的FrameLayout layout_weight编程 [英] FrameLayout layout_weight programmatically

查看:206
本文介绍了的FrameLayout layout_weight编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个的FrameLayout 编程如下(此视图将漂浮在的LinearLayout

I'm trying to create a FrameLayout programmatically as follows(this view will float on the the bottom center of a LinearLayout):

    FrameLayout bottomFrameLayout = new FrameLayout(context);
    bottomFrameLayout.setLayoutParams(new FrameLayout.LayoutParams(0,LayoutParams.FILL_PARENT,Gravity.CENTER | Gravity.BOTTOM));

由于我设置 layout_width = 0dp ,我想也设置 layout_weight 来控制宽度。我该怎么办呢?

Since I set layout_width=0dp, I would like to also set layout_weight to control the width. How can I do that?

推荐答案

您需要使用 LinearLayout.LayoutParams(INT宽度,高度INT,浮重)构造,因为的FrameLayout 的LinearLayout 因此,你正在为孩子PARAMS在的LinearLayout

You need to use LinearLayout.LayoutParams (int width, int height, float weight) constructor since FrameLayout is child of LinearLayout therefore you are setting params for child in LinearLayout.

编辑:

 FrameLayout bottomFrameLayout = new FrameLayout(context);
 LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0,LayoutParams.FILL_PARENT,mWeight);
 lp.gravity = Gravity.CENTER | Gravity.BOTTOM;
 bottomFrameLayout.setLayoutParams(lp);

这篇关于的FrameLayout layout_weight编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆