java - Aligning right in android only work for last view added -
i'm trying align right dynamically several imageviews last 1 aligned.
in order best understanding here picture:
the activity layout set way:
<scrollview android:layout_width="match_parent" android:layout_height="match_parent" android:fillviewport="true" android:id="@+id/scrollview" android:layout_below="@+id/button"> <linearlayout android:id="@+id/imagem" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > </linearlayout> </scrollview>
and in code within linearlayout called imagem add more layouts in order give me final result, here code adding single line:
linearlayout layout = (linearlayout)findviewbyid(r.id.imagem); linearlayout llay = new linearlayout(this); linearlayout comandos = new linearlayout(this); comandos.setorientation(linearlayout.horizontal); comandos.setgravity(gravity.right); llay.setorientation(linearlayout.horizontal); textview tv = new textview(this); tv.settext(titulo); tv.settypeface(null, typeface.bold); tv.settextsize(tv.gettextsize()*1.05f); textview tv2 = new textview(this); tv2.settext(descricao); layout.addview(tv); layout.addview(llay); llay.addview(tv2); imageview image = new imageview(this); image.setimagedrawable(e); comandos.addview(image, new linearlayout.layoutparams(math.round(80*reducao),math.round(60*reducao))); llay.addview(comandos, new linearlayout.layoutparams(linearlayout.layoutparams.wrap_content,linearlayout.layoutparams.wrap_content,gravity.right));
the way add several images keep creating new imageviews , adding them "comandos" layout.
is there mistake making correct alignment last line?
horizontal linearlayout not support gravity.right or left, not know "empty" space left between views.
a simple solution set textview's weight 1, "push" image right , take empty space. so:
linearlayout layout = (linearlayout)findviewbyid(r.id.imagem); linearlayout llay = new linearlayout(this); linearlayout comandos = new linearlayout(this); comandos.setorientation(linearlayout.horizontal); llay.setorientation(linearlayout.horizontal); textview tv = new textview(this); tv.settext(titulo); tv.settypeface(null, typeface.bold); tv.settextsize(tv.gettextsize()*1.05f); textview tv2 = new textview(this); tv2.settext(descricao); tv2.setlayoutparams(new linearlayout.layoutparams(0, viewgroup.layoutparams.wrap_content, 1)); // setting weight 1 layout.addview(tv); layout.addview(llay); llay.addview(tv2); imageview image = new imageview(this); image.setimagedrawable(e); image.setlayoutparams(new linearlayout.layoutparams(math.round(80*reducao),math.round(60*reducao))); comandos.addview(image); llay.addview(comandos, new linearlayout.layoutparams(linearlayout.layoutparams.wrap_content,linearlayout.layoutparams.wrap_content));
edit: did not realise adding more images comandos, fixed answer.
Comments
Post a Comment