logo
down
shadow

Advanced view animation in Android


Advanced view animation in Android

By : gewdahBear
Date : November 21 2020, 01:01 AM
like below fixes the issue I'm developing an app for Android with beautiful, but hard-to-implement design with tons of custom animations. Now I need to implement animation for button, it must be dynamic glance animation that affects both button border and its text, and must move from left to right. Here is an example of such animation in iOS app. , try this wrapper class:
code :
class FL extends FrameLayout implements ValueAnimator.AnimatorUpdateListener {
    private static final int W = 200;
    private final LinearGradient gradient;
    private final Paint paint;
    private float x;

    public FL(View child) {
        super(child.getContext());
        addView(child);
        int[] colors = {0, 0xaaffffff, 0};
        gradient = new LinearGradient(0, 0, W, 0, colors, null, Shader.TileMode.CLAMP);
        paint = new Paint();
        paint.setShader(gradient);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));
        x = -W;
    }

    @Override
    protected void dispatchDraw(Canvas canvas) {
        canvas.saveLayer(null, null, 0);
        super.dispatchDraw(canvas);
        canvas.translate(x, 0);
        float h = getHeight();
        canvas.rotate(20, W / 2, h / 2);
        canvas.drawRect(0, -h, W, 2 * h, paint);
        canvas.restore();
    }

    @Override
    public void onAnimationUpdate(ValueAnimator animation) {
        x = (int) animation.getAnimatedValue();
        invalidate();
    }

    public void startMagic() {
        ValueAnimator a = ValueAnimator.ofInt(-W, getWidth());
        a.addUpdateListener(this);
        a.setDuration(1000).setInterpolator(new AccelerateDecelerateInterpolator());
        a.start();
    }
}
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="20dp" />
    <stroke android:color="#a00" android:width="4dp" />
</shape>
    Button b = new Button(this);
    final FL fl = new FL(b);
    b.setTextSize(28);
    b.setTextColor(0xffaa0000);
    b.setText("click me to see the magic");
    b.setBackgroundResource(R.drawable.round_frame);
    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            fl.startMagic();
        }
    };
    b.setOnClickListener(listener);
    addContentView(fl, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));


Share : facebook icon twitter icon
Advanced animation with Android

Advanced animation with Android


By : user3831670
Date : March 29 2020, 07:55 AM
I hope this helps you . Sprite Animation with Android
Actually we do want a low frame rate walking for this tutorial, just like this.
Android animation shows blank view when reverse animation added

Android animation shows blank view when reverse animation added


By : MrOberle
Date : March 29 2020, 07:55 AM
this will help You don't need to dublicate your animations to achieve reverse effect. You can use android:repeateMode = "reverse" and android:repeatCount = "1"
code :
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

<rotate
    android:duration="2000"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="1"
    android:repeatMode="reverse"
    android:toDegrees="-15" />


<scale
    android:duration="2000"
    android:fromXScale="1"
    android:fromYScale="1"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="1"
    android:repeatMode="reverse"
    android:toXScale="0"
    android:toYScale="1" />

</set>
overridePendingTransition(R.anim.direct, R.anim.reversed);
Advanced linear gradient animation CSS like android swipetorefreshlayout

Advanced linear gradient animation CSS like android swipetorefreshlayout


By : Yeo Zeng
Date : March 29 2020, 07:55 AM
hope this fix your issue Since linear-gradients are, in fact, rendered images, they are not animatable (yet).
You can get the effect thinking about it in that way.
code :
    .container{
        position:relative;
        width:300px;
        height:300px;
        border:1px solid black;
    }
    .container h1{
        display:block;
        position:relative;
        z-index:2;
    }

    .animated {
        z-index:1;
        position:absolute;
        width:100%;
        height:100%;
        background: -webkit-gradient(linear, left top, right bottom, color-stop(0%, #ff670f), color-stop(21%, #ff670f), color-stop(56%, #ffffff), color-stop(88%, #0eea57));
        background: -webkit-linear-gradient(-45deg, #ff670f 0%, #ff670f 21%, #ffffff 56%, #0eea57 88%);
        background: linear-gradient(135deg, #ff670f 0%, #ff670f 21%, #ffffff 56%, #0eea57 88%);
        animation:gra1 5s infinite;
        animation-direction:alternate;
        -webkit-animation:gra1 5s infinite;
        -webkit-animation-direction:alternate;


        animation-timing-function:linear;
        -webkit-animation-timing-function:linear;
    }
    .animated2 {
        content: ' ';
        z-index:1;
        position:absolute;
        width:100%;
        height:100%;

        border:1px solid black;
        background: -webkit-gradient(linear, left top, right bottom, color-stop(0%, #ff670f), color-stop(10%, #ff670f), color-stop(40%, #ffffff), color-stop(60%, #0eea57));
        background: -webkit-linear-gradient(-45deg, #ff670f 0%, #ff670f 10%, #ffffff 40%, #0eea57 60%);
        background: linear-gradient(135deg, #ff670f 0%, #ff670f 10%, #ffffff 40%, #0eea57 60%);
        animation-direction:alternate;
        -webkit-animation:gra2 5s infinite;
        -webkit-animation-direction:alternate;

            animation-timing-function:linear;
        -webkit-animation-timing-function:linear;
    }
    .animated3 {
        content: ' ';
        z-index:1;
        position:absolute;
        width:100%;
        height:100%;

        border:1px solid black;
        background: -webkit-gradient(linear, left top, right bottom, color-stop(0%, #ff670f), color-stop(5%, #ff670f), color-stop(10%, #ffffff), color-stop(40%, #0eea57));
        background: -webkit-linear-gradient(-45deg, #ff670f 0%, #ff670f 5%, #ffffff 10%, #0eea57 40%);
        background: linear-gradient(135deg, #ff670f 0%, #ff670f 5%, #ffffff 10%, #0eea57 40%);

        animation-direction:alternate;
        -webkit-animation:gra3 5s infinite;
        -webkit-animation-direction:alternate;

            animation-timing-function:linear;
        -webkit-animation-timing-function:linear;
    }

    @-webkit-keyframes gra {
        33% {
            opacity: 1;
        }
        80% {
            opacity: 0;
        }
        100% {
            opacity:0;
        }
    }

    @-webkit-keyframes gra2 {
        33% {
            opacity: 0;
        }
        66% {
            opacity: 1;
        }
        100% {
            opacity:0;
        }
    }

@-webkit-keyframes gra3 {
    33% {
        opacity: 0;
    }
    66% {
        opacity: 0;
    }
    100% {
        opacity:1;
    }
}
.container{
    position:relative;
    width:300px;
    height:300px;
    border:1px solid black;
}
.container h1{
    display:block;
    position:relative;
    z-index:2;
}

.animated {
    z-index:1;
    position:absolute;
    width:100%;
    height:100%;
    background: -webkit-gradient(linear, left top, right bottom, color-stop(0%, #ff670f), color-stop(5%, #ff670f), color-stop(20%, #ffffff), color-stop(44%, #0eea57));
    background: -webkit-linear-gradient(-45deg, #ff670f 0%, #ff670f 5%, #ffffff 20%, #0eea57 44%);
    background: linear-gradient(135deg, #ff670f 0%, #ff670f 5%, #ffffff 20%, #0eea57 44%);
    background-size:200%;
    background-position:0px 0px;
    animation:gra1 5s infinite;
    animation-direction:alternate;
    -webkit-animation:gra1 5s infinite;
    -webkit-animation-direction:alternate;

    animation-timing-function:linear;
    -webkit-animation-timing-function:linear;

}

@-webkit-keyframes gra1 {
    33% {
            background-position:0px 0px;
    }
    66% {
        background-position:-50px -50px;
    }
    100% {
        background-position:-150px -150px;
    }
}
alpha fading animation works only once , when bottom up animation of another view finishes in Android

alpha fading animation works only once , when bottom up animation of another view finishes in Android


By : Prabhdeep Gill
Date : March 29 2020, 07:55 AM
it helps some times I’m using bottom to top animation for a stone image. I want the animation to start with a delay of 2 seconds and it should finish in 1.5 seconds. , Just put below lines in onAnimationEnd(Animation animation).
code :
if(stone.getVisibility() ==  View.GONE) {
   dust.setVisibility(View.GONE);
}
Merge Advanced View Positioning and View Animation functions

Merge Advanced View Positioning and View Animation functions


By : Luis Valdes Escobar
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Working snippet based on the second edit on Feb 15 of answer to the original question
code :
  proj4.defs("EPSG:31982","+proj=utm +zone=22 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs");
  if (ol.proj.proj4 && ol.proj.proj4.register) { ol.proj.proj4.register(proj4); }

  var view = new ol.View({
    center: [0, 0],
    zoom: 1
  });
  var map = new ol.Map({
    layers: [
      new ol.layer.Tile({
        source: new ol.source.OSM()
      })
    ],
    target: 'map',
    controls: ol.control.defaults({
      attributionOptions: {
        collapsible: false
      }
    }),
    view: view
  });

  var flytoparqueorion = document.getElementById('flytoparqueorion');
  flytoparqueorion.addEventListener('click', function() {

    var oldCenter = view.getCenter();
    var oldZoom = view.getZoom();
    var extent = ol.proj.transformExtent([565280.904542, 6924581.621580, 565319.267400, 6924554.342636], 'EPSG:31982', 'EPSG:3857');
    view.fit(extent, {padding: [170, 50, 30, 150], constrainResolution: false});
    var newCenter = view.getCenter();
    var newZoom = view.getZoom();
    view.setCenter(oldCenter);
    view.setZoom(oldZoom);

    flightZoom = Math.min(oldZoom, newZoom) - 2;
    zoomUp = oldZoom - flightZoom;
    zoomDown = newZoom - flightZoom;

    var duration = 2000;
    var parts = 2;
    var called = false;
    function callback(complete) {
      --parts;
      if (called) {
        return;
      }
      if (parts === 0 || !complete) {
        called = true;
        //done(complete);
      }
    }
    view.animate({
      center: newCenter,
      duration: duration
    }, callback);
    view.animate({
      zoom: flightZoom,
      duration: duration * zoomUp / (zoomUp + zoomDown)
    }, {
      zoom: newZoom,
      duration: duration * zoomDown / (zoomUp + zoomDown)
    }, callback);

  }, false);
  .mapcontainer {
    position: relative;
    margin-bottom: 20px;
  }
  .map {
    width: 1000px;
    height: 600px;
  }
  div.ol-zoom {
    top: 178px;
    left: 158px;
  }
  div.ol-rotate {
    top: 178px;
    right: 58px;
  }
  .map div.ol-attribution {
    bottom: 30px;
    right: 50px;
  }
  .padding-top {
    position: absolute;
    top: 0;
    left: 0px;
    width: 1000px;
    height: 170px;
    background: rgba(255, 255, 255, 0.5);
  }
  .padding-left {
    position: absolute;
    top: 170px;
    left: 0;
    width: 150px;
    height: 400px;
    background: rgba(255, 255, 255, 0.5);
  }
  .padding-right {
    position: absolute;
    top: 170px;
    left: 950px;
    width: 50px;
    height: 400px;
    background: rgba(255, 255, 255, 0.5);
  }
  .padding-bottom {
    position: absolute;
    top: 570px;
    left: 0px;
    width: 1000px;
    height: 30px;
    background: rgba(255, 255, 255, 0.5);
  }
  .center {
    position: absolute;
    border: solid 1px black;
    top: 490px;
    left: 560px;
    width: 20px;
    height: 20px;
  }
<link rel="stylesheet" href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css" type="text/css">
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.5.0/proj4.js"></script>
<div class="mapcontainer">
  <div id="map" class="map"></div>
  <div class="padding-top"></div>
  <div class="padding-left"></div>
  <div class="padding-right"></div>
  <div class="padding-bottom"></div>
  <div class="center"></div>
</div>
<button id="flytoparqueorion">Fly to Parque Orion</button>
Related Posts Related Posts :
  • Picasso does not call onBitmapLoaded for the first time
  • How can I pass an audio file as input instead of recorded voice to Google search voice?
  • How to set `ImageView`'s height to match it's width while `layout_weight` is set?
  • How to run a task once, only on installing, on android
  • ADT - Android SDK manager shows update installed with a red mark
  • Android: how to show two activity in one window using java code (not using .xml)
  • How to do independently scrolling rows and columns (a la Netflix app) on Android in a WebView?
  • Sending Data between Activities in Android periodically.
  • Classcastexception achartengine
  • Google Play shows no supported devices
  • OkHttp3 is returning timeout exception
  • What is the best camera parameters for android camera opened in surface view
  • how do i update the database table on the basis of checkbox/unchecked
  • Placeholder for contacts without name in listview
  • Storing username and password in plain text
  • Android Material default colors
  • Android studio importing in gradle issue
  • syntax error (code 1): , while compiling: CREATE TABLE
  • different behavior of app when signed with production key
  • Prevent softkeyboard dismiss on the android back button press
  • can't instantiate class... no empty constructor
  • Image Quality degrading after getting bitmap from internet and setting it to a Image View
  • Home Icon is not showing next to Hamburger icon in ActionBar
  • Layout issue with Toolbar
  • Prevent my android:theme from modifying dialogs?
  • Facebook login with Parse always returns false in user.isNew() Android
  • I get NullPointerException in an Android animation?
  • Things move out of place on different screen sizes
  • android database: the method open() is undefined for the type databasehelper class
  • sending intent with a parcelable extra from widget crashes on activity startup
  • How to record a video less than 10 mb using Android
  • Android - serialize object to pass it over Bluetooth NotSerializableException
  • Facebook Login Button Android in Eclipse
  • Null pointer exception on adding a marker to google maps
  • Jackson : Can not deserialize instance of java.util.ArrayList out of VALUE_TRUE token
  • How to customize PagerTitleStrip android
  • Click event not being captured for ListView items with HorizontalScrollView
  • HAX kernel module is not installed
  • Android: signed watchface on Android Wear 5.0 not installed
  • Dialog Builder in PreferenceFragment
  • HttpClient change UserAgent
  • Numerous 'No resource found' and 'Error retrieving parent' in Android Project
  • Get call log of a particular number
  • Invalid "--android-sdk" value "C:\android-sdk-win" in Titanium while deploying app on android mobile
  • Call onResume() method from Asynctask's onPostExecute() Method
  • Linking with native SO file present in included library project of Android
  • GridView error in horizontal spacing
  • Progressbar on bottom of listview item
  • Adding Markers on Google maps v2 Android
  • How to Remove Duplicate Libraries added via gradle?
  • Datepicker Dialog Validation...!
  • Scale image in ImageView to width of the parent and scale in height accordingly
  • user level api 19 failed to load. What files should i download
  • While running android AVD manager it shows error "HAX kernel module is not installed!"
  • Android application for limited enterprise audience
  • How to align different elements vertically in android studio?
  • Scroll View is not working when keyboard is open
  • Android phone Lg Realm(ls620) no driver found and can't find one online
  • Pros and cons for using external libraries in android project
  • What is the path of OAT file in Android 5.0
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org