0

It seems like I have a problem with java code where I want to use LayoutParams in while loop.

So in this code, I thought it might be like this but not working.

If is width and height of the image > 0 , then start looping by subtracting height and width till 0.

Does anyone have some fix for this?

Here is the code:

 public void run() {


    ViewGroup.LayoutParams params = myBall.getLayoutParams();


    while ((params.height > 0) && (params.width > 0)) {
        params.width--;
        params.height--;
        myBall.setLayoutParams(params);
}}

2 Answers2

0

Ok, try this

Create a folder named anim in your res and add anim_out.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true" >

    <scale
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="250"
        android:fromXScale="1"
        android:fromYScale="1"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="0"
        android:toYScale="0" >
    </scale>

    <alpha
        android:duration="250"
        android:fromAlpha="1"

        android:toAlpha="0" />

</set>

do this in your main java,

//Your view could be any View or ViewGroup
View view = (View) findViewById(R.id.view1);
view.setAnimation(AnimationUtils.loadAnimation(context,
                R.anim.anim_out));
 view.setVisibility(View.GONE);

Try this and tell me :). Happy coding

Ajeet
  • 1,540
  • 1
  • 17
  • 30
-1

Try doing it like this:

 public void run() {
    while ((myBall.getLayoutParams().height > 0) && (myBall.getLayoutParams().width > 0))
    {
        myBall.getLayoutParams().width--;
        myBall.getLayoutParams().height--;
    }
}

Let me know if it did the trick.

Bugs Happen
  • 2,169
  • 4
  • 33
  • 59