这是以编程方式“ WITHOUT XML ”翻译动画的简单示例,适用于Android 4.4.2。, 的所有版本,但在Android 4.4.2上无效。 这真让我疯狂!
任何想法为什么?
适用于:
EMULATOR,AVD 4.1.2(API 16),EMULATOR,AVD 4.2.2(API 17),EMULATOR,AVD 4.3.1(API 18),Galaxy Tab 3(4.1.2),Surprice, surprice .....适用于我的Galaxy NOTE和Omnirom 4.4.4不工作:
EMULATOR,AVD 4.4.2(API 19),Galaxy S4(4.4.2),Galaxy Note 3(4.4.2)
public class ActivityTypeSF extends Activity{
Graphics graphics;
FrameLayout fl;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int myWidth = 1280;
int myHeight = 800;
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
boolean isPortrait = getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
int frameBufferWidth = isPortrait ? myHeight : myWidth;
int frameBufferHeight = isPortrait ? myWidth : myHeight;
Bitmap frameBuffer = Bitmap.createBitmap(frameBufferWidth, frameBufferHeight, Config.RGB_565);
graphics = new AndroidGraphics(getAssets(), frameBuffer);
fl = new FrameLayout(this);
ImageView mons= new ImageView(this);
mons.setImageBitmap(graphics.newImage("mons/mons01.png", ImageFormat.ARGB8888).getBitmap());
mons.setX(400);
mons.setY(200);
TranslateAnimation aniTrans = new TranslateAnimation(0, 0, 0, -200);
aniTrans.setDuration(5000);
mons.setAnimation(aniTrans);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
fl.addView(mons, params);
FrameLayout.LayoutParams flp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
this.setContentView(fl, flp);
mons.startAnimation(aniTrans);
aniTrans.startNow();
}
(1)。 找到了问题,但我需要一些帮助来解决它! (注意:这只发生在完整的Java代码中。使用XML文件时不会发生,但事实并非如此)
看看这个新的示例代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
common = new Common(this, this);
FrameLayout.LayoutParams framelayoutparameter = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
/* I think that this is the line code (imageviewparamenter) were Android 4.4.2 FAILS during animation.
*/
LayoutParams imageviewparamenter = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
/*
* No matter the size of the screen, Android 4.4.2 creates a black hole outside the image size,
* just during animation (see attached picture). Thats why animation dont show up, if the
* initial position (setX or setY) of the image, is outside the image boundary.
*/
fl = new FrameLayout(this);
ImageView iv = new ImageView(this);
/* Image is located in the ASSET and is 100x100 pixels (non dpi dependable)
* "common" method use AssetManager to read the image file
*/
iv.setImageBitmap(common.newImage("iv_image.png", ImageFormat.RGB565).getBitmap());
iv.setX(50); // position show in the example
iv.setY(0);
fl.addView(iv, imageviewparamenter);
this.setContentView(fl, framelayoutparameter);
AlphaAnimation animation = new AlphaAnimation(0,1);
animation.setDuration(5000);
animation.setAnimationListener(this);
/* Also, "setAnimation(animation)" must be present, in order that
* Android 4.4.2 animates without skipping frames
*/
iv.setAnimation(animation);
iv.startAnimation(animation);
}
使用纯Java代码使用ImageView和alpha动画创建框架布局。在动画期间, Android 4.4.2(API19)在ImageView大小边界之外创建一个黑色蒙版,从x / y坐标开始(0 + imageWidth / 0 + imageHeight) ,所以如果你最初把图像放在那个坐标之外,你就看不到任何动画,只看动画结尾处的原始图像....
要重新创建此问题,我将图片放在 x = 50 中。在Android 4.4.2 动画期间,您会看到图像的右半边是黑色。您可以使用您喜欢的任何大小的屏幕设置来重新创建模拟器。使用API 16,17,18没有问题,但使用API19,黑色面具会让你发疯!
现在,有什么想法吗?或者是Android 4.4.2上的一个大错误?或者我只是看不到它?
(2。)还发现如果你不在android 4.4.2上使用setAnimation,动画会随机失败并且Choreographer会跳过帧
注意:我会发布说明问题的图片,一旦我获得更多声誉。谢谢!
已编辑:我需要上传解释此问题的图片,但由于它对新用户不太友好,只需点击此链接即可查看图片:
http://forum.xda-developers.com/showpost.php?p=56553476&postcount=2