List of usage examples for android.widget GridLayout setAlignmentMode
public void setAlignmentMode(@AlignmentMode int alignmentMode)
From source file:nz.ac.otago.psyanlab.common.designer.program.stage.EditPropPropertiesFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Bundle args = getArguments();//from w w w . j av a2s .c o m if (args.containsKey(ARG_PROP)) { mProp = args.getParcelable(ARG_PROP); } else { mProp = mCallbacks.getProp(args.getInt(ARG_PROP_ID)).getProp(); } mFieldMap = new HashMap<String, Field>(); mViewMap = new HashMap<String, View>(); // Run through the fields of the prop and build groups and mappings for // the fields and views to allow the user to change the property values. Field[] fields = mProp.getClass().getFields(); for (int i = 0; i < fields.length; i++) { Field field = fields[i]; PALEPropProperty annotation = field.getAnnotation(PALEPropProperty.class); if (annotation != null) { String fieldName = annotation.value(); View view; if (field.getType().isAssignableFrom(Integer.TYPE)) { try { view = newIntegerInputView(annotation.isSigned(), field.getInt(mProp)); } catch (IllegalArgumentException e) { throw new RuntimeException("Should never get here.", e); } catch (IllegalAccessException e) { throw new RuntimeException("Should never get here.", e); } } else if (field.getType().isAssignableFrom(Float.TYPE)) { try { view = newFloatInputView(annotation.isSigned(), field.getFloat(mProp)); } catch (IllegalArgumentException e) { throw new RuntimeException("Should never get here.", e); } catch (IllegalAccessException e) { throw new RuntimeException("Should never get here.", e); } } else if (field.getType().isAssignableFrom(String.class)) { try { view = newStringInputView((String) field.get(mProp)); } catch (IllegalArgumentException e) { throw new RuntimeException("Should never get here.", e); } catch (IllegalAccessException e) { throw new RuntimeException("Should never get here.", e); } } else { continue; } mFieldMap.put(fieldName, field); mViewMap.put(fieldName, view); if (mGroupings.containsKey(annotation.group())) { mGroupings.get(annotation.group()).add(fieldName); } else { ArrayList<String> list = new ArrayList<String>(); list.add(fieldName); mGroupings.put(annotation.group(), list); } } } // Initialise grid layout. GridLayout grid = new GridLayout(getActivity()); grid.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); grid.setAlignmentMode(GridLayout.ALIGN_BOUNDS); grid.setColumnCount(2); grid.setUseDefaultMargins(true); // Run through groupings of properties adding the created views to the // GridLayout in sections. for (String group : mGroupings.keySet()) { if (!TextUtils.isEmpty(group) && !TextUtils.equals(group, "")) { TextView sectionBreak = (TextView) inflater.inflate(R.layout.prop_property_section_break, grid, false); sectionBreak.setText(group); GridLayout.LayoutParams sectionBreakParams = new GridLayout.LayoutParams(); sectionBreakParams.columnSpec = GridLayout.spec(0, 2); sectionBreak.setLayoutParams(sectionBreakParams); grid.addView(sectionBreak); } for (String name : mGroupings.get(group)) { TextView propertyLabel = (TextView) inflater.inflate(R.layout.prop_property_label, grid, false); GridLayout.LayoutParams params = new GridLayout.LayoutParams(); propertyLabel.setLayoutParams(params); propertyLabel.setText(getResources().getString(R.string.format_property_label, name)); View propertyView = mViewMap.get(name); params = new GridLayout.LayoutParams(); params.setGravity(Gravity.FILL_HORIZONTAL); propertyView.setLayoutParams(params); grid.addView(propertyLabel); grid.addView(propertyView); } } return grid; }