J'ai 15 éléments textView et je veux aligner les uns sous les autres. Mais lorsque la taille de l'écran est étroite, certains textViews disparaissent. Comment puis-je organiser cela? (J'ai utilisé RelativeLayout.Si il y a une résolution avec d'autres Layouts, vous pouvez expliquer)comment puis-je organiser mes textViews en référence à la taille de l'écran?
Répondre
Vous pouvez créer votre propre mise en page.
Cette disposition passera automatiquement à la ligne suivante s'il n'y a pas assez d'espace. Comme float: left en html/css
public class PredicateLayout extends ViewGroup {
private int line_height;
public PredicateLayout(Context context) {
super(context);
}
public PredicateLayout(Context context, AttributeSet attrs){
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
assert(MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.UNSPECIFIED);
final int width = MeasureSpec.getSize(widthMeasureSpec);
// The next line is WRONG!!! Doesn't take into account requested MeasureSpec mode!
int height = MeasureSpec.getSize(heightMeasureSpec) - getPaddingTop() - getPaddingBottom();
final int count = getChildCount();
int line_height = 0;
int xpos = getPaddingLeft();
int ypos = getPaddingTop();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() != GONE) {
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
child.measure(
MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST),
MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST));
final int childw = child.getMeasuredWidth();
line_height = Math.max(line_height, child.getMeasuredHeight() + lp.height);
if (xpos + childw > width) {
xpos = getPaddingLeft();
ypos += line_height;
}
xpos += childw + lp.width;
}
}
this.line_height = line_height;
if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.UNSPECIFIED){
height = ypos + line_height;
} else if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST){
if (ypos + line_height < height){
height = ypos + line_height;
}
}
setMeasuredDimension(width, height);
}
@Override
protected LayoutParams generateDefaultLayoutParams() {
return new LayoutParams(30, 30); // default of 1px spacing
}
@Override
protected boolean checkLayoutParams(LayoutParams p) {
return (p instanceof LayoutParams);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
final int count = getChildCount();
final int width = r - l;
int xpos = getPaddingLeft();
int ypos = getPaddingTop();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() != GONE) {
final int childw = child.getMeasuredWidth();
final int childh = child.getMeasuredHeight();
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
if (xpos + childw > width) {
xpos = getPaddingLeft();
ypos += line_height;
}
child.layout(xpos, ypos, xpos + childw, ypos + childh);
xpos += childw + lp.width;
}
}
}
}
Mais lorsque la taille de l'écran est réduite, certains textView disparaissent. Comment puis-je organiser cela?
Utilisez un ScrollView
pour rendre l'interface utilisateur scrollable.
Ahmad est correct, vous voulez envelopper votre mise en page ScrollView. –
Merci..Puis-je fixé sans 'ScrollView'? –
- 1. Comment organiser mes servlets?
- 2. android - Comment organiser les deux textviews côte à côte
- 3. Comment organiser mes documents?
- 4. Comment organiser mes vues de gâteau
- 5. ASP.NET Runtime organiser mes contrôles
- 6. Comment dois-je organiser mes modèles mvc?
- 7. Comment organiser mes thèmes ASP.Net et mes fichiers CSS communs?
- 8. je dois organiser mes connaissances
- 9. Comment dois-je organiser mes données?
- 10. Organiser mes types récursifs mutuels
- 11. Qu'ai-je fait pour mes TextViews?
- 12. Comment réduire la taille de mes onglets?
- 13. Comment organiser le code en utilisant une référence d'assembly optionnelle?
- 14. TextViews à l'intérieur d'une boucle
- 15. Comment organiser mes paquets java dans notre projet web mvc?
- 16. Comment organiser verticalement des UILabels de taille dynamique?
- 17. Comment devrais-je organiser mes fonctions avec pyparsing?
- 18. Comment référencer TextViews à l'intérieur de LinearLayout?
- 19. Comment dois-je organiser mes fichiers dans Xcode?
- 20. Comment puis-je organiser mes ressources dans des dossiers?
- 21. Déclarer dynamiquement TextViews
- 22. GWT + JDO + GAE, comment organiser mes données pour une performance
- 23. ontouchlisteners à textviews
- 24. comment puis-je organiser la sortie de mes données que j'utilise la concaténation de groupe?
- 25. Comment organiser correctement la sortie en colonnes?
- 26. référence ambiguë à Cocos2d-x Taille type
- 27. Comment organiser deux rangées de boutons de même taille en utilisant MigLayout imbriqué dans un ScrollPane
- 28. Dans Xna, comment réduire la taille de mes textures?
- 29. Comment organiser mon code en 'modules'?
- 30. Comment ajouter TextViews à un ListView
Je vais essayer. Merci... –