How to change the height of a view

by jdekeij » Wed, 11 Nov 2009 03:53:08 GMT


Sponsored Links
 I use the following layout to define a gameboard.

<LinearLayout xmlns:android=" http://schemas.android.com/apk/res/ 
android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <gomoku.com.BoardView
android:id="@+id/gomoku"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>

All works fine, however I want the gameboard to appear as square. So I
need to resize the board at runtime to put it in the center of the
screen and make it square. I tried many options without success :(

Help is very much appreciated

Thanks,
Jasper de Keijzer

--



How to change the height of a view

by RichardC » Wed, 11 Nov 2009 04:06:46 GMT


 I can answer 1/2 your question




You need to implement onMeasure  in your custom view class and call
setMeasuredDimension when you have calculated the largest square your
want your custom view to occupy.

Centering a view in its parent container I do not know how to do.

--
RichardC




--


Sponsored Links