LinearLayout.LayoutParam不再具有addRule函数或LinearLayout.Bottom吗? [英] LinearLayout.LayoutParam no longer have addRule function nor LinearLayout.Bottom?
问题描述
我正在动态创建一些视图并插入LinearLayout中.我计划将其从上到下按顺序插入. (默认情况下,它会插入到底部和顶部).
I'm creating some views dynamically and insert into a LinearLayout. I'm planning to insert it from the Top to Bottom orderly. (by default, it insert at Bottom and to the Top).
我在 https://stackoverflow.com/a/12290985/3286489 中找到了该指南.
I found the guide here https://stackoverflow.com/a/12290985/3286489.
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.mylayout);
TextView txt1 = new TextView(MyClass.this);
LinearLayout.LayoutParams layoutParams =
(RelativeLayout.LayoutParams) txt1.getLayoutParams();
layoutParams.addRule(LinearLayout.BOTTOM, 1);
txt1.setLayoutParams(layoutParams);
linearLayout.addView(txt1);
但是,当我尝试使用它时,显然找不到LinearLayout的addRule
函数和LinearLayout.BOTTOM
值.我有什么想念吗?
However, when I try it, apparently there's no more addRule
function nor LinearLayout.BOTTOM
value for LinearLayout found. Did I miss anything?
推荐答案
显然,没有LinearLayout.BOTTOM之类的东西,我们也无法为LinearLayout添加规则.
Apparently there is no such thing as LinearLayout.BOTTOM, nor can we add rule for LinearLayout.
但是好消息是将其插入LinearLayout中,可以确定顺序.只需使用addView
函数和以下3个参数
But the good news is to insert into LinearLayout, one could decide the sequence.. Just use the addView
function with 3 arguments as below
mLayout.addView(view, index, param);
index
确定了顺序.
这篇关于LinearLayout.LayoutParam不再具有addRule函数或LinearLayout.Bottom吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!