Problem with sample Snake

Discussion in 'Application Development' started by james23, Oct 4, 2009.

  1. james23

    james23 New Member
    5

    Oct 3, 2009
    1
    0
    5
    Hi, everyone

    I'm new to android, just began to learn it a few days ago, but when I tried to learn from the built-in sample source "Snake", I noticed it's just a custom view extending "android.view.View", and it doesn't override the "onMeasure(int widthMeasureSpec, int heightMeasureSpec)", the method from its parent class View, which is supposed to be a must according to android's dev guide, I quote here:

    "You will almost certainly want to override onMeasure() and are also likely to need to override onDraw() if you want the component to show something. While both have default behavior, the default onDraw() will do nothing, and the default onMeasure() will always set a size of 100x100
     

    Advertisement
  2. jackmang

    jackmang New Member
    5

    Nov 14, 2009
    1
    0
    5
    I'm seeing the same thing. The only way the board size gets set is by changing the default values in the code. Changing the value in the xml has no effect. Does anyone know the source of this bug?

    I'm a C# developer trying to learn Java in Android and I'm less than a week into this so the sample/tutorials are key learning points.
     
  3. javiarie

    javiarie New Member
    5

    Jan 24, 2010
    1
    0
    5
    Hi everyone, I'm also a newbie since a week right now, and I came to a possible solution:

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:snake="http://schemas.android.com/apk/res/com.example.android.snake"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >


    <com.example.android.snake.SnakeView
    android:id="@+id/snake"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    snake:tileSize="48"
    />


    Hope someone find it useful
     
  4. galth

    galth Member
    16

    Aug 5, 2010
    12
    1
    16
    This one was driving me nuts. Thanks for the solution. Hopefully, someone will fix their samples.
     

Share This Page

Loading...