(Android) Set Width/Height of (Image-)Button in Java Class -


i want set width , height of imagebutton in java class, width of button should width of display / 4, height of button should height of display / 4.

code:

    protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          display display = getwindowmanager().getdefaultdisplay();         point size = new point();         display.getsize(size);         int width = size.x;         int height = size.y;          imagebutton button = (imagebutton) findviewbyid(r.id.imagebutton);         // button.setwidth(width/4)         // button.setheight(height/4)     } 

apparently there's no method button called setwidth() or setheight(), how can accomplish it?

possible weight looking for. example code give 4 rectangles, takes quarter of screen

<linearlayout         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:orientation="vertical">          <linearlayout             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_weight="1">              <view                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_weight="1"                 android:background="@android:color/black"/>              <view                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_weight="1"                 android:background="@android:color/white"/>         </linearlayout>          <linearlayout             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_weight="1">             <view                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_weight="1"                 android:background="@android:color/holo_red_dark"/>              <view                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_weight="1"                 android:background="@android:color/holo_blue_bright"/>         </linearlayout>     </linearlayout> 

you can define weightsum in linearlayout , views scaled percent of weightsum.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -