android interface error ImageButton -


hi have app gallery of images.

the problem that, have buttons move between images on center of app , want them @ 75% of margin of top.

the question : can put on % of screen instead of dp?

the error if use margin_bottom crashes.

here code

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@color/color_fondo" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context=".mainactivity" >  <imageview     android:id="@+id/barra"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentleft="true"     android:layout_alignparentright="true"     android:layout_alignparenttop="true"     android:scaletype="fitxy"a     android:src="@drawable/cabecera" />  <imageview     android:id="@+id/img1"     android:layout_width="wrap_content"     android:layout_height="match_parent"     android:layout_alignparentbottom="true"     android:layout_alignparentleft="true"     android:layout_alignparentright="true"     android:layout_below="@+id/barra"     android:paddingtop="@dimen/activity_vertical_margin"     android:scaletype="fitxy"     android:src="@drawable/ic_launcher" />  <progressbar     android:id="@+id/pb1"     style="?android:attr/progressbarstylelarge"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_aligntop="@+id/img1"     android:layout_centerhorizontal="true"     android:visibility="invisible" />  <imagebutton     android:id="@+id/imgbtnshare1"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentbottom="true"     android:layout_centerhorizontal="true"     android:background="@null"     android:paddingbottom="5dp"     android:src="@drawable/compartir4" />  <imagebutton     android:id="@+id/imgbtn2"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_above="@+id/imgbtnshare1"     android:layout_alignparentleft="true"     android:layout_marginbottom="100dp"     android:background="@null"     android:src="@drawable/izquierda42" />  <imagebutton     android:id="@+id/imgbtn1"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentright="true"     android:layout_aligntop="@+id/imgbtn2"     android:background="@null"     android:src="@drawable/derecha42" />  </relativelayout> 

you may layout size , calculate buttons top margin proportion of that:

note: cannot layout size in oncreate() since it's not set yet. in onwindowfocuschanged method of activity.

relativelayout relativelayout = (relativelayout)findviewbyid(r.id.yourxml);  @override public void onwindowfocuschanged (boolean hasfocus) {         // layout has been drawn here          // height , width have been computed          int width = relativelayout.getwidth();         int height = relativelayout.getheight();  }  int topmargin = height * 0.75; 

and set programmatically:

layoutparams layoutparams = new layoutparams(                                   layoutparams.wrap_content,                                         layoutparams.wrap_content                             );  layoutparams.setmargins(left, top, right, bottom); yourbutton.setlayoutparams(layoutparams); 

Comments