vendredi 15 mai 2015

Android how to set two textview one in right and the other has left

I created my textview dynamically, I would like first to display the left and one to right dynamically all this in a for loop and here's some of my code

final LinearLayout ll = (LinearLayout) findViewById(R.id.container_LV);

                            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams
                                    (
                                    RelativeLayout.LayoutParams.MATCH_PARENT,
                                    RelativeLayout.LayoutParams.MATCH_PARENT
                                    );

                            for (int i = 0; i < fields.length(); i++) 
                            {

                                final TextView txtLabel = new TextView(getApplicationContext());
                                final TextView txtValue = new TextView(getApplicationContext());

                                jsonLabel = fields.getJSONObject(i).getString(TAG_LABEL) ; //+ "\n";
                                jsonValue = fields.getJSONObject(i).getString(TAG_VALUE) ; //+ "\n";

                                txtLabel.setLayoutParams(params);
                                txtValue.setLayoutParams(params);

                                txtLabel.setGravity(Gravity.LEFT  );
                                txtValue.setGravity(Gravity.RIGHT );

                                //params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT,0);

                                txtLabel.setText(jsonLabel);
                                txtValue.setText(jsonValue);
                                txtLabel.setTextColor(Color.WHITE);
                                txtValue.setTextColor(Color.WHITE);

                                //txtLabel.


                                ll.addView(txtLabel);
                                ll.addView(txtValue);
                            }

Thank You .

Aucun commentaire:

Enregistrer un commentaire