我有一个frameLayout
并且在这个布局里面有几个视图,我想把每个视图从顶部边缘到一个特定的距离。我已经尝试了以下代码,但似乎它不起作用
FrameLayout lytBoard = (FrameLayout) findViewById(R.id.lytBoard);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width, height);
params.setMargins((int)board.cells.get(i).x1, (int)board.cells.get(i).y1, 0, 0);
CellView cv = new CellView(getApplicationContext());
cv.setLayoutParams(params);
lytBoard.addView(cv);
单元格视图类:
public class CellView extends View {
public CellView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int size = Math.min(getMeasuredWidth(), getMeasuredHeight());
setMeasuredDimension(size, size);
}
}