Can I Set “android:layout_below” at Runtime Programmatically?

前端 未结 4 2091
被撕碎了的回忆
被撕碎了的回忆 2020-11-27 11:06

Is it possible when creating a RelativeLayout at runtime to set the equivalent of android:layout_below programmatically?

4条回答
  •  臣服心动
    2020-11-27 11:58

    While @jackofallcode answer is correct, it can be written in one line:

    ((RelativeLayout.LayoutParams) viewToLayout.getLayoutParams()).addRule(RelativeLayout.BELOW, R.id.below_id);
    

提交回复
热议问题