Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="@drawable/easymap"
- android:orientation="vertical" >
- <TextView
- android:id="@+id/whitePlayer"
- android:layout_width="32dp"
- android:layout_height="32dp"
- android:background="@drawable/white"
- android:visibility="gone" />
- <TextView
- android:id="@+id/blackPlayer"
- android:layout_width="32dp"
- android:layout_height="32dp"
- android:background="@drawable/black"
- android:visibility="gone" />
- <Button
- android:id="@+id/btRoll"
- android:layout_width="160dp"
- android:layout_height="50dp"
- android:layout_alignParentLeft="true"
- android:layout_alignTop="@+id/cubePic"
- android:background="@drawable/buttonshape"
- android:text="Roll"
- android:textColor="#FFFFFF" />
- <TextView
- android:id="@+id/cubePic"
- android:layout_width="100dp"
- android:layout_height="100dp"
- android:layout_alignParentBottom="true"
- android:layout_alignParentRight="true"
- android:layout_marginBottom="42dp"
- android:layout_marginRight="22dp"
- android:background="@drawable/cube" />
- <TextView
- android:id="@+id/tvTurn"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignBottom="@+id/cubePic"
- android:layout_alignRight="@+id/btRoll"
- android:text="Your turn!"
- android:textColor="@color/green"
- android:textSize="32dp"
- android:textStyle="italic" />
- </RelativeLayout>
- The java class:
- package com.example.snakesnladders;
- import android.app.Activity;
- import android.content.Context;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.graphics.Canvas;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.SurfaceHolder;
- import android.view.SurfaceView;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.TextView;
- public class GFX_Game extends Activity implements OnClickListener {
- TextView whitePlayer, blackPlayer;
- Button roll;
- TextView cube, map1, map2, map3, label;
- boolean yourTurn = true;
- MyBringBack ourView;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- ourView = new MyBringBack(this);
- setContentView(ourView);
- init();
- }
- private void init() {
- cube = (TextView) findViewById(R.id.cubePic);
- roll = (Button) findViewById(R.id.btRoll);
- label = (TextView) findViewById(R.id.tvTurn);
- roll.setOnClickListener(this);
- }
- @Override
- protected void onDestroy() {
- super.onDestroy();
- }
- @Override
- public void onClick(View view) {
- int rand = (int) (Math.random() * 6) + 1;
- }
- class MyBringBack extends SurfaceView implements Runnable {
- SurfaceHolder ourHolder;
- Thread ourThread = null;
- Bitmap backGround, playerB, playerW;
- boolean isRunning = true;
- public MyBringBack(Context context) {
- super(context);
- playerW = BitmapFactory.decodeResource(getResources(),
- R.id.whitePlayer);
- ourHolder = getHolder();
- ourThread = new Thread(this);
- ourThread.start();
- }
- @Override
- public void run() {
- while (isRunning) {
- if (!ourHolder.getSurface().isValid())
- continue;
- Canvas canvas = ourHolder.lockCanvas();
- canvas.drawBitmap(playerW, 0, 0, null);
- ourHolder.unlockCanvasAndPost(canvas);
- }
- }
- }
- }
- class MyBringBack extends View {
- Bitmap playerW;
- public MyBringBack(Context context) {
- super(context);
- playerW = BitmapFactory.decodeResource(getResources(),
- R.id.whitePlayer);
- }
- @Override
- protected void onDraw(Canvas canvas) {
- // TODO Auto-generated method stub
- super.onDraw(canvas);
- canvas.drawBitmap(playerW,0,0,null);
- }
- }
- public final class MyRelativeLayout extends RelativeLayout {
- Bitmap playerW;
- public MyRelativeLayout(Context context) {
- super(context);
- init(context);
- }
- public MyRelativeLayout(Context context, AttributeSet attrs) {
- super(context, attrs);
- init(context);
- }
- public MyRelativeLayout(Context context, AttributeSet attrs, int style) {
- super(context, atts, style);
- init(context);
- }
- private void init(final Context context) {
- playerW = BitmapFactory.decodeResource(context.getResources(),
- R.id.whitePlayer);
- }
- @Override
- protected void onDraw(Canvas canvas) {
- super.onDraw(canvas);
- canvas.drawBitmap(playerW,0,0,null);
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <your.package.name.package.MyRelativeLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- ...
- all the stuff here
- <your.package.name.package.MyRelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement