Ejemplo n.º 1
0
  private void initResource() {
    Bitmap tileBitMap1 =
        BitmapFactory.decodeResource(getResources(), R.drawable.hills_distance_0_portrait);
    Bitmap tileBitMap2 =
        BitmapFactory.decodeResource(getResources(), R.drawable.hills_distance_1_portrait);
    Bitmap bgMap = BitmapFactory.decodeResource(getResources(), R.drawable.night_sky_portrait);
    midBg = new BitmapDrawable(tileBitMap1);
    forBg = new BitmapDrawable(tileBitMap2);
    bg = new BitmapDrawable(bgMap);

    midBg.setTileModeX(TileMode.REPEAT);
    forBg.setTileModeX(TileMode.REPEAT);
    bg.setTileModeX(TileMode.REPEAT);
  }
  private AnimationDrawable getAnimation(Bitmap bitmap) {
    AnimationDrawable animation = new AnimationDrawable();
    animation.setOneShot(false);

    List<Bitmap> shiftedBitmaps = getShiftedBitmaps(bitmap);
    int duration = 50;

    for (Bitmap image : shiftedBitmaps) {
      BitmapDrawable navigationBackground = new BitmapDrawable(getResources(), image);
      navigationBackground.setTileModeX(TileMode.REPEAT);

      animation.addFrame(navigationBackground, duration);
    }
    return animation;
  }