如何从活动中获取视图的边距值?视图可以是任何类型。
经过一番搜索后,我找到了填充视图的方法,但在 Margin 上找不到任何内容。有人可以帮忙吗?
我尝试过这样的事情,
ViewGroup.LayoutParams vlp = view.getLayoutParams();
int marginBottom = ((LinearLayout.LayoutParams) vlp).bottomMargin;
这是可行的,但在上面的代码中我假设视图是LinearLayout
。但我需要得到margin
即使我不知道视图类型,也可以使用属性。
尝试这个:
View view = findViewById(...) //or however you need it
LayoutParams lp = (LayoutParams) view.getLayoutParams();
边距可通过
lp.leftMargin;
lp.rightMargin;
lp.topMargin;
lp.bottomMargin;
edit:也许ViewGroup.MarginLayoutParams
会为你工作。这是其他的基类LayoutParams
.
ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
http://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html http://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)