我正在開發中,我創建像RadioButton
,CheckBox
,EditText
動態基於json
響應和使用Java編程增加LinearLayout
觀點Android應用程序無法正常工作。 在micromax A114中,我得到了預期的結果! 。Android的 - 創建視圖動態預期
但是,當我測試Samsung note edge
它崩潰,看起來不好。
。
下面是我用
for (int dynamicViews = 0; dynamicViews < FormFieldsController
.initializeFormFieldsController().initializeFormFields().size(); dynamicViews++){
int fieldType = Integer.parseInt(formFields.getFieldType());
switch (fieldType) {
case VIEW_TYPE_EDIT_TEXT:
LinearLayout fieldLabel = new LinearLayout(context);
fieldLabel.setOrientation(LinearLayout.VERTICAL);
params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, 40);
params.setMargins(10, 10, 0, 0);
TextView label = new TextView(context);
label.setBackground(context.getResources().getDrawable(
R.drawable.text_area_field_title_background));
label.setTextColor(Color.parseColor("#FFFFFF"));
label.setPadding(10, 5, 10, 0);
label.setText(formFields.getFieldName());
label.setLayoutParams(params);
fieldLabel.addView(label);
params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, 200);
final EditText editText = new EditText(context);
editText.setGravity(Gravity.CENTER);
params.setMargins(10, 0, 10, 10);
editText.setLayoutParams(params);
editText.setBackground(context.getResources().getDrawable(
R.drawable.cornerless_rc_bg));
editText.setHint("Type Here ...");
if (formFields.getCrfFormField().getFieldValue() != null) {
editText.setText(formFields.getCrfFormField()
.getFieldValue());
}
editText.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
FormFieldsController.initializeFormFieldsController()
.initializeFormFields().get(position)
.getCrfFormField()
.setFieldValue(editText.getText().toString());
}
@Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
// TODO Auto-generated method stub
}
});
fieldLabel.addView(editText);
container.addView(fieldLabel);
break;
}
}
視圖的高度是固定的(40),但所有設備上的像素密度都不相同。也許你需要根據屏幕密度動態計算高度? – 2Dee