0
我做了一个自定义视图以满足我对显示数学向量的简单方法的需求。 我扩展了一个LinearLayout并为这些值添加了一个ArrayList。每次更改值时,我都会调用我的自定义方法redraw()将EditText添加到LinearLayout。在添加一个值之后,再次添加所有现有的EditText。如何清除LinearLayout或显示新的LinearLayout?在自定义视图中处理布局
这里是一些代码:
public Vector(Context context, AttributeSet attrs) {
super(context, attrs);
setWillNotDraw(false);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (inflater != null) {
inflater.inflate(R.layout.vector, this);
}
}
public void redraw() {
for (Float value : getArray()) {
EditText edit = new EditText(getContext());
edit.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.FILL_PARENT));
edit.setText(value.toString());
((LinearLayout) findViewById(R.id.root)).addView(edit);
}
}