我有一个RelativeLayout
的孩子,我正在尝试修改Java中的布局参数。我得到LayoutParams
如下:
RelativeLayout.LayoutParams dlp = (LayoutParams) dimBackground.getLayoutParams();
dlp.addRule(RelativeLayout.BELOW, currentTextView.getId());
//dlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
dimBackground.setLayoutParams(dlp);
行dlp.addRule(RelativeLayout.BELOW, currentTextView.getId());
不会更改dimBackground
的位置,但如果我取消注释下面的行,那么dimBackground
将在父视图的底部对齐。
知道为什么第一条规则不起作用?
修改:
正如所建议的那样,我尝试了xml,仍然没有运气。下面是我的xml:
<RelativeLayout
android:id="@+id/dim_background_bottom"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:layout_below="@+id/product_subtotal_row"
android:background="@color/gray_tint"
android:visibility="visible" />
答案 0 :(得分:2)
(由于你没有发布太多关于你的布局的细节......很难给你一个明确的答案)。
我猜你的currentTextView
和你的dimBackground
没有相同的父亲RelativeLayout。
正如RelativeLayout doc中提到的那样:
一种布局,其中儿童的位置可以相互描述或与父母相关。
因此请仔细检查currentTextView
和dimBackground
是否属于同一个RelativeLayout
的孩子