Je crée dynamiquement une TextView à partir de Activity. J'ai créé 2 Textviews et je veux maintenir un certain écart entre 2 TextViews. Comment cela peut-il être réalisé par le code plutôt que par XML? Normalement, en XML, nous utilisons android: layout_marginLeft/Right tag pour maintenir l'écart entre 2 TextViews. Comment cela peut-il être réalisé grâce au code?
Merci à l'avance,Comment utiliser android: Layout_marginLeft dynamiquement dans Android pour TextView
2
A
Répondre
2
Cela dépend de la mise en page que vous utilisez. Cet exemple met un RelativeLayout dans un LinearLayout
LinearLayout linearLayoutParent;
RelativeLayout relativeLayout;
RelativeLayout.LayoutParams margin = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
margin.setMargins(0, 0, 0, 7); //7px bottom margin
//get or create the linear and the relative layouts
...
// Add view with its margins
linearLayoutParent.addView(relativeLayout, margin);
2
ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
layoutParams.setMargins(10, 10, 10, 10);
view.setLayoutParams(layoutParams);
Questions connexes
- 1. Android: onTouchEvent pour textView
- 2. Comment faire pour arrondir TextView dans Android?
- 3. Android TextView pour afficher l'ancre
- 4. comment textview et android
- 5. Android TextView
- 6. Comment régler dynamiquement la hauteur de textview android
- 7. android n'affiche pas "" dans TextView?
- 8. Défilement TextView dans Android Widget
- 9. Formatage Android TextView
- 10. Android TextView Minuterie
- 11. Android AutoComplete TextView
- 12. Comment convertir TextView en EditText dans android?
- 13. Android Autocomplte Textview Filtrage
- 14. android textview fill parent
- 15. Android textview et Menu
- 16. Android: Augmentation de la hauteur de textview dynamiquement
- 17. Android TextView lien sans souligné?
- 18. android lier string_array à textview
- 19. Hyperliens en ligne dans Android TextView
- 20. Modifier dynamiquement l'indicateur d'onglet dans Android
- 21. TextView sur Horizontal ScrollView dans android?
- 22. Android: "nowrap" dans Spannable dans TextView
- 23. Justifier le texte dans TextView Android
- 24. comment ajouter dynamiquement enfant à tablerow dans android?
- 25. Android Textview Italique et wrap_contents
- 26. Android de style appliquer à TextView personnalisé
- 27. Réutiliser le code TextView dans Android XML
- 28. drag n drop textview dans Android
- 29. Android - hauteur dynamique TextView d'émission
- 30. Comment définir la couleur d'un TextView dans Android?
Merci, ur suggestion a fonctionné pour moi. –