Search Results

Search found 10 results on 1 pages for 'user270811'.

Page 1/1 | 1 

  • android spinning image

    - by user270811
    hi, i am trying to create two spinning wheels, as in pulleys, so everytime the attached rope moves, the two pulleys will rotate. i have tried two approaches: 1) use Matrix.postRotate within the onDraw() method of the View class, which calls the following: private void drawSpinningWheel(Canvas canvas) { try { canvas.save(); Bitmap bitmapOrg = null; int iDrawable = R.drawable.spinning_button; bitmapOrg = BitmapFactory.decodeResource(getResources(), iDrawable); if(bitmapOrg != null) { int width = bitmapOrg.getWidth(); int height = bitmapOrg.getHeight(); int newWidth = 24; int newHeight = 24; // calculate the scale - in this case = 0.4f float scaleWidth = ((float) newWidth) / width; float scaleHeight = ((float) newHeight) / height; // createa matrix for the manipulation Matrix matrix = new Matrix(); // resize the bit map matrix.postScale(scaleWidth, scaleHeight); matrix.postRotate((float) mDegrees++); Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width, height, matrix, true); canvas.drawBitmap(resizedBitmap, matrix, null); } canvas.restore(); } catch(Exception e) { Log.e(TAG + "drawSpinningWheel", e.getMessage()); } } but it seems like the image not only spins but rotates around another axis 2) use SurfaceView and a separate thread, in the run() call this: private void doDraw(Canvas canvas) { // Draw the background image. Operations on the Canvas accumulate // so this is like clearing the screen. canvas.drawBitmap(mBackgroundImage, 0, 0, null); int yTop = mCanvasHeight - ((int) mY + mSpinningWheelImageHeight / 2); int xLeft = (int) mX - mSpinningWheelImageWidth / 2; ... // Draw the ship with its current rotation canvas.save(); canvas.rotate((float) mHeading++, (float) mX, mCanvasHeight - (float) mY); mSpinningWheelImage.setBounds(xLeft, yTop, xLeft + mSpinningWheelImageWidth, yTop + mSpinningWheelImageHeight); mSpinningWheelImage.draw(canvas); canvas.restore(); } i get the spinning to work but i can't add another spinning wheel. i even tried to create another thread for the second spinning wheel, only one shows up. can someone point me in the right direction? thanks.

    Read the article

  • custom view with layout

    - by user270811
    ok, what i am trying to do is to embed a custom view in the default layout main.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <com.lam.customview.CustomDisplayView android:id="@+id/custom_display_view1" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"> <Button android:id="@+id/prev" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="50" android:textAppearance="?android:attr/textAppearanceSmall" android:text="@string/prev" /> </LinearLayout> </LinearLayout> as you can see the class is called com.lam.customview.CustomDisplayView, with the id of custom_display_view1. now in the com.lam.customview.CustomDisplayView class, i want to use another layout called custom_display_view.xml because i don't want to programmatically create controls/widgets. custom_display_view.xml is just a button and an image, the content of which i want to change based on certain conditions: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/display_text_view1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <ImageView android:id="@+id/display_image_view1" android:layout_width="wrap_content" android:layout_height="wrap_content"> </ImageView> </LinearLayout> i tried to do: 1) public CustomDisplayView(Context context, AttributeSet attrs) { super(context, attrs); try { // register our interest in hearing about changes to our surface SurfaceHolder holder = getHolder(); holder.addCallback(this); View.inflate(context, R.layout.custom_display_view, null); ... but got this error, "03-08 20:33:15.711: ERROR/onCreate(10879): Binary XML file line #8: Error inflating class java.lang.reflect.Constructor ". 2) public CustomDisplayView(Context context, AttributeSet attrs) { super(context, attrs); try { // register our interest in hearing about changes to our surface SurfaceHolder holder = getHolder(); holder.addCallback(this); View.inflate(context, R.id.custom_display_view1, null); ... but got this error, "03-08 20:28:47.401: ERROR/CustomDisplayView(10806): Resource ID #0x7f050002 type #0x12 is not valid " also, if i do it this way, as someone has suggested, it's not clear to me how the custom_display_view.xml is associated with the custom view class. thanks.

    Read the article

  • how to do android image animation

    - by user270811
    hi, i am trying to get a simple image animation going. i want to make it looks as if the helicopter's propeller blades are turning. i have 3 images for the helicopter, and i am showing one of these images depending on the animation progress. the problem is that all three images end up overlapping each other as opposed to just one image showing up at one time, thereby creating the animation. this is what i did so far, i even tried to clear canvas by doing this canvas.drawColor(Color.BLACK), but that would clear out the whole canvas, which is not what i want. this is what i have: 1) in the View class: static class Helicopter { private long mLastUpdate; private long mProgress = 0; private final float mX; private final float mY; private final Bitmap mHelicopter1; private final Bitmap mHelicopter2; private final Bitmap mHelicopter3; private final float mRadius; Helicopter(long mLastUpdate, float mX, float mY, Bitmap helicopter1, Bitmap helicopter2, Bitmap helicopter3) { this.mLastUpdate = mLastUpdate; this.mX = mX; this.mY = mY; this.mHelicopter1 = helicopter1; this.mHelicopter2 = helicopter2; this.mHelicopter3 = helicopter3; mRadius = ((float) mHelicopter1.getWidth()) / 2f; } public void update(long now) { mProgress += (now - mLastUpdate); if(mProgress >= 400L) { mProgress = 0; } mLastUpdate = now; } public void setNow(long now) { mLastUpdate = now; } public void draw(Canvas canvas, Paint paint) { if (mProgress < 150L) { canvas.drawBitmap(mHelicopter1, mX - mRadius, mY - mRadius, paint); } else if (mProgress < 300L) { canvas.drawBitmap(mHelicopter2, mX - mRadius, mY - mRadius, paint); } else if(mProgress < 400L) { canvas.drawBitmap(mHelicopter3, mX - mRadius, mY - mRadius, paint); } } public boolean done() { return mProgress > 700L; } } private ArrayList<Helicopter> mHelicopters = new ArrayList<Helicopter>(); 2) this is being called in the run() of a thread: private void doDraw(Canvas canvas) { final long now = SystemClock.elapsedRealtime(); canvas.save(); for (int i = 0; i < mHelicopters.size(); i++) { final Helicopter explosion = mHelicopters.get(i); explosion.update(now); } for (int i = 0; i < mHelicopters.size(); i++) { final Helicopter explosion = mHelicopters.get(i); explosion.draw(canvas, mPaint); } canvas.restore(); } can someone help me? i have looked at a lot of the examples on the web on animation, they seem to always involve text, but not images. thanks.

    Read the article

  • View Animation (Resizing a Ball)

    - by user270811
    hi, i am trying to do this: 1) user long touches the screen, 2) a circle/ball pops up (centered around the user's finger) and grows in size as long as the user is touching the screen 3) once the user lets go of the finger, the ball (now in its final size) will bounce around. i think i have the bouncing around figure out from the DivideAndConquer example, but i am not sure how to animate the ball's growth. i looked at various view flipper examples such as this: http://www.inter-fuser.com/2009/08/android-animations-3d-flip.html but it seems like view flipper is best for swapping two static pictures. i wasn't able to find a good view animator example other than the flippers. also, i would prefer to use images as opposed to just a circle. can someone point me in the right direction? thanks.

    Read the article

  • how to pause and stop a changing ImageView

    - by user270811
    hi, i have an ImageView in which the picture switches every 5s, i am trying to add a pause and resume button that can stop and restart the action. i am using a Handler, Runnable, and postDelay() for image switch, and i put the code on onResume. i am thinking about using wait and notify for the pause and resume, but that would mean creating an extra thread. so far for the thread, i have this: class RecipeDisplayThread extends Thread { boolean pleaseWait = false; // This method is called when the thread runs public void run() { while (true) { // Do work // Check if should wait synchronized (this) { while (pleaseWait) { try { wait(); } catch (Exception e) { } } } // Do work } } } and in the main activity's onCreate(): Button pauseButton = (Button) findViewById(R.id.pause); pauseButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { while (true) { synchronized (thread) { thread.pleaseWait = true; } } } }); Button resumeButton = (Button) findViewById(R.id.resume); resumeButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { while (true) { // Resume the thread synchronized (thread) { thread.pleaseWait = false; thread.notify(); } } } }); the pause button seems to work, but then after that i can't press any other button, such as the resume button. thanks.

    Read the article

  • Programmatically set layout for android

    - by user270811
    Hi, I am trying to improve the layout for my game. The problem is that while I can create a good layout for one android phone, it doesn't work for another, ie the trackball for MyTouch is on the right side (landscape mode), but for the MyCliq, the DPad is on the left side. Is there a way to programmatically set the layout based on which phone it is? Thanks.

    Read the article

  • android phone's scroll ball, D-Pad not working

    - by user270811
    hi, i have a Cliq and a MyTouch phone. i am writing a game that requires a fire button. on the cliq, it's the center of the D-Pad, and on the MyTouch, the scroll ball. i am handling the onKeyDown events via a separate thread. it all works until i press the button too many times, meaning the key down event is no longer fired off. if i press the D-Pad down or scroll the ball down, then the fire button works again. i can only guess that maybe the message queue within the OS is full, therefore the fire button temporarily malfuntions. can someone help me? thanks.

    Read the article

  • programmtically set layout for android

    - by user270811
    hi, i am trying to improve the layout for my game. the problem is that while i can create a good layout for one android phone, it doesn't work for another, ie the trackball for MyTouch is on the right side (landscape mode), but for the MyCliq, the DPad is on the left side. is there a way to programmatically set the layout based on which phone it is? thanks.

    Read the article

1