Note that there are some explanatory texts on larger screens.

plurals
  1. PORelativeLayout and canvas costum view
    primarykey
    data
    text
    <p>I would like to make an activity with this structure:</p> <p><img src="https://i.stack.imgur.com/2uCu7.png" alt="Desired layout"> The idea is to put some text in the top, a banner allways in the top, the button OVER the banner and my canvas in the center of the view, using all the possible space.</p> <p>I'm subclassing View to draw my canvas and overloading the onMeasure() method:</p> <pre><code>@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // Calculate the size of the board this.squareSize = MeasureSpec.getSize(widthMeasureSpec) / BOARD_NUM_ROWS; this.leftMargin = (MeasureSpec.getSize(widthMeasureSpec) - squareSize*BOARD_NUM_COLUMNS) / 2; this.topMargin = this.leftMargin; // Set the size of the board to full width and aspect ratio height int desiredWidth = MeasureSpec.getSize(widthMeasureSpec); int desiredHeight = this.topMargin + (BOARD_NUM_ROWS * this.squareSize) + this.topMargin; this.setMeasuredDimension(desiredWidth, desiredHeight); } </code></pre> <p>And this is my XML:</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" android:layout_width="fill_parent" android:layout_height="fill_parent" tools:context=".DrawLevelActivity" android:background="@color/activity_background"&gt; &lt;TextView android:id="@+id/instructionsText" android:gravity="center" android:paddingTop="10dp" android:paddingBottom="10dp" android:paddingLeft="0dp" android:paddingRight="0dp" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; &lt;com.mycanvas.BoardCanvas android:id="@+id/boardCanvas" android:gravity="center" android:layout_below="@+id/instructionsText" android:layout_centerVertical="true" android:padding="0dp" android:layout_width="wrap_content" android:layout_height="wrap_content" /&gt; &lt;Button android:id="@+id/solveButton" android:gravity="center" android:paddingTop="10dp" android:paddingBottom="10dp" android:paddingLeft="30dp" android:paddingRight="30dp" android:layout_below="@+id/boardCanvas" android:layout_width="fill_parent" android:layout_height="wrap_content"/&gt; &lt;com.google.ads.AdView xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads" android:id="@+id/adView" android:gravity="center" android:paddingTop="0dp" android:paddingBottom="0dp" android:paddingLeft="0dp" android:paddingRight="0dp" android:layout_alignParentBottom="true" android:layout_width="fill_parent" android:layout_height="wrap_content" googleads:adSize="BANNER" googleads:adUnitId="@string/admob_id" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>Unfortunately the button appear under the banner and I think that the reason is that the canvas is very large.</p> <p>The set value in onMeasure() is always smaller than MeasureSpec.getSize(heightMeasureSpec)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload