4
我在設置保證金時遇到了一些問題!在Android中爲LinearLayout添加保證金
body_content = (LinearLayout) findViewById(R.id.body_content);
int gSLength = 2;
body_content.setPadding(10, 0, 10, 0);
for (int i = 0; i < 1; i++){
FrameLayout fl = new FrameLayout(this);
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, 90);
fl.setLayoutParams(params);
LinearLayout ll1 = new LinearLayout(this);
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 30);
params1.setMargins(0, 60, 0, 0);
ll1.setLayoutParams(params1);
ll1.setBackgroundDrawable(getResources().getDrawable(R.drawable.line_down));
fl.addView(ll1);
body_content.addView(fl);
}
它不工作params1.setMargins (0, 60, 0, 0);
你是什麼意思,它不工作?你有沒有嘗試向父母添加填充? – lc2817
從'LinearLayout.LayoutParams'改變'params1'的類型爲'FrameLayout.LayoutParams' –
也許你可以使用... params1.leftmarin等.., – Udaykiran