• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Problem with sample Snake

james23

Lurker
Oct 3, 2009
1
0
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
 
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.
 
Upvote 0
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
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones