imageview - Android: align two images -
i'm trying put 2 imageview
in linearlayout
, don't align it. want them appear:
|<----space---->image 1<----space---->image 2<----space---->|
but 2 images on left without margin. code:
java
int terciopantalla = modulo.anchopantalla(this) / 3; linearlayout.layoutparams layoutparams2 = new linearlayout.layoutparams(terciopantalla, terciopantalla / 2); layoutparams2.gravity = gravity.center; ruta1.setlayoutparams(layoutparams2); linearlayout.layoutparams layoutparams3 = new linearlayout.layoutparams(terciopantalla, terciopantalla / 2); layoutparams3.gravity = gravity.center; ruta2.setlayoutparams(layoutparams3);
modulo.anchopantalla
public static int anchopantalla(context context) { int ancho = 0; displaymetrics metrics = context.getresources().getdisplaymetrics(); ancho = (int) (metrics.widthpixels); return ancho; }
xml
<linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margintop="5dp" android:orientation="horizontal" > <imageview android:id="@+id/bus_ruta1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/ruta1_selector" /> <imageview android:id="@+id/bus_ruta2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/ruta2_selector" /> </linearlayout>
try this..
<linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margintop="5dp" android:orientation="horizontal" > <imageview android:id="@+id/bus_ruta1" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:src="@drawable/ruta1_selector" /> <imageview android:id="@+id/bus_ruta2" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:src="@drawable/ruta2_selector" /> </linearlayout>
edit:
linearlayout.layoutparams lp_icon = new linearlayout.layoutparams(0, linearlayout.layoutparams.wrap_content, 1); ruta1.setlayoutparams(lp_icon); ruta2.setlayoutparams(lp_icon);
Comments
Post a Comment