我正在设计动态布局,其中我添加了spinner
,edittext
和button
。它显示适用于AVD,但它会根据设备更改而更改。这是我的代码。
Spinner newMobileSpinner = new Spinner(CustomerDetails.this);
newMobileSpinner.setLayoutParams(new
LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT, 0.2f
)
);
newMobileSpinner.setAdapter(arrayAdpType);
EditText newMobileEditText = new EditText(CustomerDetails.this);
newMobileEditText.setLayoutParams(new
LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT, 1.2f
)
);
newMobileEditText.getLayoutParams().width=0;
newMobileEditText.setHint("Mobile No");
newMobileEditText.setBackgroundDrawable(
getResources().getDrawable(android.R.drawable.editbox_background_normal)
);
newMobileEditText.setInputType(InputType.TYPE_CLASS_NUMBER |
InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED);
Button newBtnRemove = new Button(CustomerDetails.this);
newBtnRemove.setLayoutParams(new LinearLayout.LayoutParams(20,45, 0.15f));
newBtnRemove.setBackgroundResource(R.drawable.minusred);
final LinearLayout Matrix = (LinearLayout)findViewById(R.id.sub5);
final LinearLayout layout = new LinearLayout(CustomerDetails.this);
layout.setOrientation(LinearLayout.HORIZONTAL);
layout.addView(newMobileSpinner);
layout.addView(newMobileEditText);
layout.addView(newBtnRemove);
Matrix.addView(layout);
请帮帮我。
答案 0 :(得分:1)
// try this way,hope this will help you...
Spinner newMobileSpinner = new Spinner(this);
newMobileSpinner.setLayoutParams(new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.WRAP_CONTENT, 1f));
newMobileSpinner.setAdapter(arrayAdpType);
EditText newMobileEditText = new EditText(this);
newMobileEditText.setLayoutParams(new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.WRAP_CONTENT, 1f));
newMobileEditText.setHint("Mobile No");
newMobileEditText.setBackgroundResource(android.R.drawable.editbox_background_normal);
newMobileEditText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED);
Button newBtnRemove = new Button(this);
newBtnRemove.setLayoutParams(new LinearLayout.LayoutParams(0,45, 1f));
newBtnRemove.setBackgroundResource(R.drawable.minusred);
LinearLayout Matrix = (LinearLayout)findViewById(R.id.sub5);
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.HORIZONTAL);
layout.addView(newMobileSpinner);
layout.addView(newMobileEditText);
layout.addView(newBtnRemove);
Matrix.addView(layout);