gpt4 book ai didi

android - 以编程方式相对布局

转载 作者:行者123 更新时间:2023-11-30 04:46:33 25 4
gpt4 key购买 nike

我有一个相对布局,它包含一个 Button 和一个 EditText

在页面加载时,我正在像这样初始化相对布局

RelativeLayout bottomLayout;
bottomLayout = (RelativeLayout) findViewById(R.id.s_r_l_bottom);
RelativeLayout.LayoutParams layoutParams =
(RelativeLayout.LayoutParams) bottomLayout .getLayoutParams();
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, -1);
bottomLayout.setLayoutParams(layoutParams );

因此,我的相对布局位于屏幕底部。现在我正在尝试在屏幕顶部也有 Button

通过按下按钮,我希望相对布局位于屏幕的中央

为此,我在单击按钮时使用了以下代码(代码正在执行。我已经测试过了)。但它对我没有帮助。

RelativeLayout.LayoutParams layoutParams = 
(RelativeLayout.LayoutParams) bottomLayout.getLayoutParams();
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, -1);
bottomLayout.setLayoutParams(layoutParams);

你能帮我解决这个问题吗?

最佳答案

您确定在按下按钮后不会同时有两个规则:底部规则和中间规则吗?因此他们互相混淆...

关于android - 以编程方式相对布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4814196/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com