android - 仅按右侧和顶部值设置边距

标签 android layout margins

此问题与在屏幕上定位对象有关。我使用下面给出的布局参数动态创建了框架布局

 FrameLayout fl=new FrameLayout(getApplicationContext());
 LayoutParams frameBounds=new FrameLayout.LayoutParams(500,500);
 fl1.setLayoutParams(frameBounds);
 Button b=newButton(this);
 b.setMargins(0,0,200,200);

我试过它有效,但我的按钮往往停留在左上角。有没有办法通过只考虑右值和下值而不考虑左值和上值来定位按钮。简而言之,我希望按钮的右角距离 framelayout(500) 的右角 200。帮助PLZ ...

最佳答案

您必须在底部|右侧设置重力。然后,将边距200。

关于android - 仅按右侧和顶部值设置边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8593381/

相关文章:

android - 微调器返回 null

css - 使用 flexbox,使用安全吗?随时随地使用它?

html - Bootstrap 面板在 IE-8 中显示为左对齐

css - 在 Chrome 中打印会更改我的页面布局

css - Firefox 和 Safari 的边距

android - 在 android studio canary -2 中找不到版本代码

android - eclipse 无法在设备上安装 apk, "ActivityManager:/sbin/sh: am: not found"

android - @react-native-firebase/admob 的基本用法给出 : "TypeError: (0, _admob.default) is not a function". 是否已弃用?或为什么不起作用?

android - 图像大小问题,同时以编程方式添加