android - Strange layout issue -


i using relative layout, , section taken it:

<imageview     android:id="@+id/btnlifeminus5"     android:layout_width="50dp"     android:layout_height="50dp"     android:background="#2a80b9"     android:visibility="invisible"     android:adjustviewbounds="false"     android:clickable="true"     android:croptopadding="false"     android:padding="0dp"     android:scaletype="fitstart"     android:layout_marginleft="0dp"     android:layout_margintop="0dp" />  <imageview     android:id="@+id/btnlifeplus5"     android:layout_width="50dp"     android:layout_height="50dp"     android:background="#2a80b9"     android:visibility="invisible"     android:adjustviewbounds="false"     android:clickable="true"     android:croptopadding="false"     android:padding="0dp"     android:scaletype="fitstart"     android:layout_marginleft="0dp"     android:layout_margintop="0dp" />  <imageview     android:id="@+id/btnlifeplus1"     android:layout_width="50dp"     android:layout_height="50dp"     android:background="#2a80b9"     android:visibility="invisible"     android:adjustviewbounds="false"     android:clickable="true"     android:croptopadding="false"     android:padding="0dp"     android:scaletype="fitstart"     android:layout_marginleft="0dp"     android:layout_margintop="0dp" />  <imageview     android:id="@+id/btnlifeminus1"     android:layout_width="50dp"     android:layout_height="50dp"     android:background="#2a80b9"     android:visibility="invisible"     android:adjustviewbounds="false"     android:clickable="true"     android:croptopadding="false"     android:padding="0dp"     android:scaletype="fitstart"     android:layout_marginleft="0dp"     android:layout_margintop="0dp" />  <textview     android:id="@+id/txtlifeplus5"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:visibility="invisible"     android:adjustviewbounds="false"     android:clickable="true"     android:croptopadding="false"     android:textcolor="#000000"     android:text="+5"     android:padding="0dp" />  <textview     android:id="@+id/txtlifeplus1"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:visibility="invisible"     android:adjustviewbounds="false"     android:clickable="true"     android:croptopadding="false"     android:textcolor="#000000"     android:text="+1"     android:padding="0dp" />  <textview     android:id="@+id/txtlifeminus5"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:visibility="invisible"     android:adjustviewbounds="false"     android:clickable="true"     android:croptopadding="false"     android:textcolor="#000000"     android:text="-5"     android:padding="0dp" />  <textview     android:id="@+id/txtlifeminus1"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:visibility="invisible"     android:adjustviewbounds="false"     android:clickable="true"     android:croptopadding="false"     android:textcolor="#000000"     android:text="-1"     android:padding="0dp" /> 

i have following method in class sets these buttons on screen. section places text onto buttons:

private void settextplacements() {     final float scale = getresources().getdisplaymetrics().density;     final textview txtplus1 = (textview) findviewbyid(r.id.txtlifeplus1);     final textview txtplus5 = (textview) findviewbyid(r.id.txtlifeplus5);     final textview txtminus1 = (textview) findviewbyid(r.id.txtlifeminus1);     final textview txtminus5 = (textview) findviewbyid(r.id.txtlifeminus5);     final imageview btnplus5 = (imageview) findviewbyid(r.id.btnlifeplus5);     final imageview btnplus1 = (imageview) findviewbyid(r.id.btnlifeplus1);     final imageview btnminus5 = (imageview) findviewbyid(r.id.btnlifeminus5);     final imageview btnminus1 = (imageview) findviewbyid(r.id.btnlifeminus1);      relativelayout.layoutparams txtp1 = new relativelayout.layoutparams(txtplus1.getlayoutparams());     txtp1.leftmargin = math.round((btnplus1.getleft() + (btnplus1.getwidth()/2)) - (txtplus1.getwidth()/2));     txtp1.topmargin = math.round((btnplus1.gettop() + (btnplus1.getheight()/2)) - (txtplus1.getheight()/2));     txtplus1.setlayoutparams(txtp1);      relativelayout.layoutparams txtp5 = new relativelayout.layoutparams(txtplus5.getlayoutparams());     txtp5.leftmargin = math.round((btnplus5.getleft() + (btnplus5.getwidth()/2)) - (txtplus5.getwidth()/2));     txtp5.topmargin = math.round((btnplus5.gettop() + (btnplus5.getheight()/2)) - (txtplus5.getheight()/2));     txtplus5.setlayoutparams(txtp5);      relativelayout.layoutparams txtm1 = new relativelayout.layoutparams(txtminus1.getlayoutparams());     txtm1.leftmargin = math.round((btnminus1.getleft() + (btnminus1.getwidth()/2)) - (txtminus1.getwidth()/2));     txtm1.topmargin = math.round((btnminus1.gettop() + (btnminus1.getheight()/2)) - (txtminus1.getheight()/2));     txtminus1.setlayoutparams(txtm1);      relativelayout.layoutparams txtm5 = new relativelayout.layoutparams(txtminus5.getlayoutparams());     txtm5.leftmargin = math.round((btnminus5.getleft() + (btnminus5.getwidth()/2)) - (txtminus5.getwidth()/2));     txtm5.topmargin = math.round((btnminus5.getleft() + (btnminus5.getwidth()/2)) - (txtminus5.getwidth()/2));     txtminus5.setlayoutparams(txtm5); } 

there lot going on in app, , working except 1 thing: txtlifeminus5 seems sitting underneath btnlifeminus5 , cannot figure out why. set identically else have done in layouts throughout entire app, 1 doesn't behave properly.

i working on assumption items listed higher in layout xml document sit underneath items below it... heckcheese going on here?

it's not issue text not being visible, have experimented displaying in different places on screen. sits on btnlifeminus5 button, vanishes underneath.

argh! thoughts?

oh god, idiot. sorry everyone. answer simple, , there no bug layout order @ all. code:

relativelayout.layoutparams txtm5 = new relativelayout.layoutparams(txtminus5.getlayoutparams()); txtm5.leftmargin = math.round((btnminus5.getleft() + (btnminus5.getwidth()/2)) - (txtminus5.getwidth()/2)); txtm5.topmargin = math.round((btnminus5.getleft() + (btnminus5.getwidth()/2)) - (txtminus5.getwidth()/2)); txtminus5.setlayoutparams(txtm5); 

is different of code:

relativelayout.layoutparams txtp1 = new relativelayout.layoutparams(txtplus1.getlayoutparams()); txtp1.leftmargin = math.round((btnplus1.getleft() + (btnplus1.getwidth()/2)) - (txtplus1.getwidth()/2)); txtp1.topmargin = math.round((btnplus1.gettop() + (btnplus1.getheight()/2)) - (txtplus1.getheight()/2)); txtplus1.setlayoutparams(txtp1);  relativelayout.layoutparams txtp5 = new relativelayout.layoutparams(txtplus5.getlayoutparams()); txtp5.leftmargin = math.round((btnplus5.getleft() + (btnplus5.getwidth()/2)) - (txtplus5.getwidth()/2)); txtp5.topmargin = math.round((btnplus5.gettop() + (btnplus5.getheight()/2)) - (txtplus5.getheight()/2)); txtplus5.setlayoutparams(txtp5);  relativelayout.layoutparams txtm1 = new relativelayout.layoutparams(txtminus1.getlayoutparams()); txtm1.leftmargin = math.round((btnminus1.getleft() + (btnminus1.getwidth()/2)) - (txtminus1.getwidth()/2)); txtm1.topmargin = math.round((btnminus1.gettop() + (btnminus1.getheight()/2)) - (txtminus1.getheight()/2)); txtminus1.setlayoutparams(txtm1); 

see it? failing section references width should referencing height. sends text object miles off screen. epic logic fail. sorry waste of time :(


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -