0
我有一個frameLayout
,在這個佈局中有幾個視圖,我想從頂部到特定距離保留每個視圖。 我曾嘗試下面的代碼,但它似乎不工作視圖Layout_Margin在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);
細胞View類:
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);
}
}
在框架佈局中添加視圖不是一個好習慣。您不能,而不是添加相對佈局 – AkashG 2012-07-13 11:57:12