我想在一個線性佈局內動態創建一個相對佈局。這個相對佈局包含一個文本視圖和按鈕,它們也是在動態方法中創建的。文本視圖和按鈕的對齊方式無法正常工作我試過的代碼在下面給出。android動態創建相互重疊的佈局
final LinearLayout lab_linear = (LinearLayout) findViewById(R.id.contact_list_layout);
lab_linear.setOrientation(LinearLayout.VERTICAL);
for (int i = 0; i < Size_contact; i++)
{
RelativeLayout layout = new RelativeLayout(this);
RelativeLayout.LayoutParams lp = new
RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
layout.setLayoutParams(lp);
final TextView Questions_value = new
android.widget.TextView(getApplicationContext());
Questions_value.setText(contact_name.get(i));
Questions_value.setTextSize(18);
Questions_value.setId(i);
layout.addView(Questions_value);
Button myButton = new Button(this);
myButton.setBackgroundResource(R.drawable.close);
myButton.setLayoutParams(new LayoutParams(20,20));
layout.addView(myButton);
lab_linear.addView(layout);
}
你想要的佈局是什麼? – Gabe
您並不特定於您的需求。 – AndroidHacker