我检查了很多答案,但迄今为止没有人帮忙.
我正在尝试扩展android的TextView并在代码中设置此自定义视图的边距,因为我将在按钮按下和类似的事情上实例化它们.它被添加到LinearLayout.那就是我得到的:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
任何地方都没有任何保证金
编辑:我可能想添加,如果我在xml中分配一个边距值,它确实有效.