android - how can I arrange my textViews with reference to screen size? -
i have 15 textview elements , want align 1 under other. when screen size narrow, textviews disappear. how can arrange this? (i've been using relativelayout. if there solving others layouts, can explain)
you can create own layout.
this layout auto flow next line if there not enough space. float:left in 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); // next line wrong!!! doesn't take 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(); (int = 0; < 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(); (int = 0; < 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; } } } }
Comments
Post a Comment