Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>i can help you in easy way.</p> <p>first take <strong>images</strong> in which you want to show ads.if you want to show image as <strong>admob</strong> (google ads) then take image <strong>320X50</strong> resolution.</p> <p>then create folder <strong>anim</strong> in res.</p> <p>in <strong>anim</strong> create animation file like <strong>anim1.xml</strong></p> <pre><code>&lt;set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"&gt; &lt;translate android:fromXDelta="-300%" android:toXDelta="0%" android:fromYDelta="0%" android:toYDelta="0%" android:duration="1000" /&gt; </code></pre> <p></p> <p>then create another file <strong>anim2.xml</strong> </p> <pre><code>&lt;set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"&gt; &lt;translate android:fromXDelta="300%" android:toXDelta="0%" android:fromYDelta="0%" android:toYDelta="0%" android:duration="1000" /&gt; </code></pre> <p></p> <p>use this file in image for animation. like</p> <pre><code>mAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.anim1); mAnimation1 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.anim2); </code></pre> <p>here i use two images which change alternatively in some regular interval.for that i use <strong>Timer</strong>.</p> <p><strong>new Timer().scheduleAtFixedRate(new UpdateTimeTask(), 1, 10 * 1000);</strong></p> <p>it call TimerTast class at fix schedule. here i call this class in every 10 second by (10 * 1000). for that first create new class <strong>UpdateTimerTast</strong></p> <pre><code>class UpdateTimeTask extends TimerTask { public void run() { // Toast.makeText(mActivity, "Timer", Toast.LENGTH_LONG).show(); Message toMain = handler.obtainMessage(); toMain.obj = "banner"; handler.sendMessage(toMain); } } </code></pre> <p>this class call Handler in which change and animate image in regular interval.</p> <p>in Handler</p> <pre><code>private Handler handler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); if (msg.obj.toString().contentEquals("banner")) { if (mBanner.isShown()) { mBanner.setVisibility(View.GONE); mBanner1.setVisibility(View.VISIBLE); mBanner1.startAnimation(mAnimation1); } else if (mBanner1.isShown()) { mBanner.setVisibility(View.VISIBLE); mBanner.startAnimation(mAnimation); mBanner1.setVisibility(View.GONE); } } </code></pre> <p>Here mBanner1 and mBanner is ImageView.</p> <p>that's it. done. :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload