vendredi 19 mai 2017

dynamically aligning checkbox with relativelayout

Im a newbie,in my project i want to align checkboxes horizontally with using Relative layout.I know,its easier with Linear layout..please,help me.. in my case,the checkboxes pasted on a same position` Main = (RelativeLayout) dialogLayout.findViewById(R.id.linearr);

                RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

                LinkedHashMap<String, String> alphabet = new LinkedHashMap<String, String>();
                alphabet.put("1", "A");
                alphabet.put("2", "B");
                alphabet.put("3", "C");
                alphabet.put("4", "D");
                alphabet.put("5", "A");
                alphabet.put("6", "B");
                alphabet.put("7", "C");
                alphabet.put("8", "D");

                Set<?> set = alphabet.entrySet(); // Get an iterator

                Iterator<?> i = set.iterator(); // Display elements
                while (i.hasNext()) {
                    @SuppressWarnings("rawtypes")


                    Map.Entry me = (Map.Entry) i.next();

                    checkBox = new CheckBox(getContext());
                    checkBox.setId(Integer.parseInt(me.getKey().toString()));
                    checkBox.setText(me.getValue().toString());
                    params.rightMargin = 30;
                    if(Integer.parseInt(me.getKey().toString())==1)
                        params.addRule(RelativeLayout.ALIGN_LEFT);
                    else
                        params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT,Integer.parseInt(me.getKey().toString())-1);

                    checkBox.setLayoutParams(params);

                   Main.addView(checkBox, params);

`




Aucun commentaire:

Enregistrer un commentaire