如何以编程方式为LinearLayout指定layout_below?

ADK*_*ADK 3 android android-layout

我想以编程方式执行此类操作 -

<RelativeLayout1>
  <LinearLayout name = 1>
  <LinearLayout below = 1>
<RelativeLayout1>
Run Code Online (Sandbox Code Playgroud)

我试着这样做:

LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)mButtonContainer.getLayoutParams();
Run Code Online (Sandbox Code Playgroud)

params有weight田野,width田野,但没有layout_below...感谢您的帮助!

Bla*_*elt 12

addRule

RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
relativeParams.addRule(RelativeLayout.BELOW, idOfTheViewBelow);
Run Code Online (Sandbox Code Playgroud)

  • @ADK:你得到`LinearLayout`的当前`RelativeLayout.LayoutParams`,然后修改它们.或者,如果这是一个新创建的`LinearLayout`,则会在答案显示时创建一个新的`RelativeLayout.LayoutParams`.`LayoutParams`的类由*parent*(`RelativeLayout`)决定,而不是*child*(`LinearLayout`). (2认同)