【发布时间】:2013-07-19 06:39:49
【问题描述】:
我检查了很多答案,但到目前为止都没有帮助。
我正在尝试扩展 android 的 TextView 并在代码中设置此自定义视图的边距,因为我将在按钮按下和类似的事情上实例化它们。它被添加到一个线性布局。这就是我得到的:
public class ResultsView extends TextView {
public ResultsView(Context context) {
super(context);
LinearLayout.LayoutParams layout = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layout.setMargins(15, 15, 15, 15);
setLayoutParams(layout);
}
}
任何地方都没有边距迹象。
编辑:我可能想补充一下,如果我在 xml 中分配一个边距值,它确实有效。
【问题讨论】: