首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >以编程方式对ImageView不起作用的底边距

以编程方式对ImageView不起作用的底边距
EN

Stack Overflow用户
提问于 2014-09-23 07:10:54
回答 1查看 354关注 0票数 0

marginBottom不起作用。它可以工作,但是不管应用了多少空间,边际空间都是很小的。为什么?

Java-代码:

代码语言:javascript
复制
LinearLayout onepage= (LinearLayout) findViewById(R.id.onepage);

RelativeLayout bluegreen = new RelativeLayout(this);
p_ll = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
bluegreen.setLayoutParams(p_ll);

//some other views that make up the whole page

//bottom most image
ImageButton migs = new ImageButton(this);
p_rl = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
p_rl.addRule(RelativeLayout.CENTER_HORIZONTAL);
p_rl.setMargins(0, 0, 0, 20);
register.setLayoutParams(p_rl);
register.setImageResource(R.drawable.migs);
register.setPadding(0, 0, 0, 0);

bluegreen.addView(migs);

onepage.addView(bluegreen);

XML:

代码语言:javascript
复制
<LinearLayout
    android:id="@+id/onepage"
    android:layout_width="match_parent"
    android:layout_height="match_parent"        
    android:orientation="vertical"
    tools:context=".PageActivity" >
</LinearLayout>
EN

回答 1

Stack Overflow用户

发布于 2014-09-23 08:29:21

您注意到了吗,在setMargins方法中,参数以像素为单位,而不是在dp中?看看android文档页面

因此,取决于您的设备屏幕大小,但20 px可以非常小。

不要忘记调用requestLayout()来考虑保证金变化。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25989036

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档