gpt4 book ai didi

android - 相对布局中的边距

转载 作者:太空狗 更新时间:2023-10-29 15:15:39 24 4
gpt4 key购买 nike

如何使用代码(不是 XML)在相对布局中设置边距?

我使用这段代码但没有任何反应:

RelativeLayout rlDetail = new RelativeLayout(context);
rlDetail.setBackgroundResource(R.drawable.bg_round);
RelativeLayout.LayoutParams rlDetailParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
rlDetailParams.setMargins(35, 10, 35, 0);
rlDetail.setLayoutParams(rlDetailParams);

最佳答案

试试这个答案 set the absolute position of a view in Android

如上链接所述,您应该使用

TextView tv1 = new TextView(context);

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(30, 40);
params.leftMargin = needed_margin;
params.topMargin = needed_margin;

// add your textview like this
rl.addView(tv1, params);

关于android - 相对布局中的边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13009233/

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