Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>My previous method had problem with memory consume. I had improved it to use TranslateAnimation. BUT it has little LAG (pay attention on HACK comment in ProgressBgView.initAnimation method)</p> <p>Layout xml :</p> <pre><code> &lt;com.example.tweenanimation.ProgressBgView android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/progress_db_view" /&gt; </code></pre> <p>Backend :</p> <pre><code> final ProgressBgView prog = (ProgressBgView) findViewById(R.id.progress_db_view); prog.setBackgroundAsTile(R.drawable.bg_tile_1); prog.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { prog.startAnimation(); } }); </code></pre> <p>And the class :</p> <pre><code>public class ProgressBgView extends FrameLayout { private ImageView mProgressImage; private TranslateAnimation mProgressAnimation; public ProgressBgView(Context context, AttributeSet attrs) { super(context, attrs); mProgressImage = new ImageView(getContext()); FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT); mProgressImage.setLayoutParams(layoutParams); addView(mProgressImage); } public void setBackgroundAsTile(int tileImageResId) { Bitmap tileBitmap = BitmapFactory.decodeResource(getResources(), tileImageResId); BitmapDrawable tileRepeatedBitmap = new BitmapDrawable(getResources(), tileBitmap); tileRepeatedBitmap.setTileModeX(TileMode.REPEAT); initAnimation(tileBitmap.getWidth()); mProgressImage.setBackgroundDrawable(tileRepeatedBitmap); } private void initAnimation(int tileImageWidth) { FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) mProgressImage.getLayoutParams(); layoutParams.setMargins(-tileImageWidth, 0, 0, 0); // *HACK* tileImageWidth-3 is used because of *lags*(slow pause) in the moment // of animation END-RESTART. mProgressAnimation = new TranslateAnimation(0, tileImageWidth - 3, 0, 0); mProgressAnimation.setInterpolator(new LinearInterpolator()); mProgressAnimation.setDuration(1000); mProgressAnimation.setRepeatCount(Animation.INFINITE); } public void startAnimation() { mProgressImage.startAnimation(mProgressAnimation); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

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