I am working on an app, which can run on Froyo
as well as JellyBean
. I have a class that extends PageTransformer as below:
import android.support.v4.view.ViewPager.PageTransformer;
import android.view.View;
public class ZoomOutPageTransformer implements PageTransformer {
private static float MIN_SCALE = 0.85f;
private static float MIN_ALPHA = 0.5f;
public void transformPage(View view, float position) {
int pageWidth = view.getWidth();
int pageHeight = view.getHeight();
if (position < -1) {
view.setAlpha(0);
} else if (position <= 1) {
float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
float vertMargin = pageHeight * (1 - scaleFactor) / 2;
float horzMargin = pageWidth * (1 - scaleFactor) / 2;
if (position < 0) {
view.setTranslationX(horzMargin - vertMargin / 2);
} else {
view.setTranslationX(-horzMargin + vertMargin / 2);
}
view.setScaleX(scaleFactor);
view.setScaleY(scaleFactor);
view.setAlpha(MIN_ALPHA +
(scaleFactor - MIN_SCALE) /
(1 - MIN_SCALE) * (1 - MIN_ALPHA));
} else {
view.setAlpha(0);
}
}
}
The problem is, the methods written in this class were added in API level 11
and i have minimum sdk version of API level 8
. The following are those methods that were added in API level 11:
setAlpha()
setTranslationX()
setScaleX()
setScaleY()
What can be the solution for this problem ?
so, some resolutions here:
setAlphaAnimation … API LEVEL 1
AlphaAnimation alpha = new AlphaAnimation(0.7F, 0.7F);
alpha.setDuration(0); // Make animation instant
alpha.setFillAfter(true); // Tell it to persist after the animation ends
view.startAnimation(alpha);
setAlpha INT -> From API LEVEL 1 -> deprecated in 16
Drawable background = localLinLayout.getBackground();
background.setAlpha(180); //255 is max (visible)
setAlpha
FLOAT -> API Level 11+ ->
setImageAlpha
-> API LEVEL 16+ (use just for ImageViews)