安卓4.4.2仅在完整的Java code动画创建一个黑色面罩外的视图对象的边界,面罩、视图、边界、创建一个

2023-09-07 14:29:29 作者:你是我触摸不了的痛

真的需要一些帮助在此...

Really need some help on this...

请看看这个简单的淡入动画的ImageView的,采用完整的Java code。使用API​​的21,18,17,16 ..完美的作品重新创建它。

Please take a look to this simple FadeIn animation of an ImageView, using full java code. Recreate it using API's 21, 18, 17, 16.. works perfect. Now try it with API 19 (android 4.4.2), funny mask created (see explanation bellow):

public class _ExampleAnimationNotWorking extends Activity {
Common common; // my own class to read assets
FrameLayout fl;
ImageView iv;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.common = new Common(this,this);
    this.fl = new FrameLayout(this);
    this.iv = new ImageView(this);

    FrameLayout.LayoutParams flparam = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,FrameLayout.LayoutParams.MATCH_PARENT);
    LayoutParams lparam = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    iv.setImageBitmap(common.newImage("iv_image.png", ImageFormat.RGB565).getBitmap());
    iv.setX(50);
    iv.setY(0);

    fl.addView(iv, lparam);
    this.setContentView(fl, flparam);

    AlphaAnimation animation = new AlphaAnimation(0,1);
    animation.setDuration(3000);
    iv.setAnimation(animation); // may skip frames if not used in API19 (thats another problem)
    iv.startAnimation(animation);
} ....

在动画过程中,安卓4.4.2(API19)是创建ImageView的大小边界外的黑色面罩,起点为x / y坐标(0 + ImageWidth等/ 0 + imageHeight),因此,如果您最初将图像以外的坐标,你看不到任何动画,只是原始图像的animation.To年底重建的问题,我已经把图像中的X = 50。你会看到一半右边的图像是在安卓4.4.2动画黑色。您可以重新使用模拟器,你preFER任何尺寸的屏幕设置与

During animation, Android 4.4.2 (API19) is creating a black mask outside the ImageView size boundary, starting at x/y coordinates (0 + imageWidth / 0 + imageHeight), so if you initially place the image outside that coordinate, you don’t see any animation, just the original image at the end of the animation.To recreate the issue, I have placed the image in x = 50 . You would see that the half right side of the image is black during Android 4.4.2 animation. You can recreate using emulator with any size of screen setup that you prefer.

从WRAP_CONTENT更改LPARAM来MATCH_PARENT或其它宽/高是解决不了问题。它应该以同样的方式,在其他版本(请注意我尝试也在4.4.3和4.4.4和完美的作品)。这可能是对4.4.2的Java code动画中的错误,因为如果你使用XML的方法,它的工作完美的API19。我需要一个解决方案或解决这一点,因为我的整个项目是基于纯Java code,并不能排除奇巧4.4.2作为该项目的目标。

Changing "lparam" from WRAP_CONTENT to MATCH_PARENT or other width/height is not the solution. It should the same way that in other versions (Note i try it also in 4.4.3 and 4.4.4 and works perfect). This maybe a bug on 4.4.2 java code animation, because if you use XML method, it work perfect on API19. I need a solution or work around on this, because my entire project is based on pure java code, and can't exclude KitKat 4.4.2 as a target on the project.

感谢。

PD:>有人在这里为了什么?这是确定的纠正我的职务,但以我-2点是什么?是不是解决我的问题,而更多的,如​​果我需要一些点附加与此问题相关的图像。谢谢CBredlow!

PD:> Some people are here for what?. It was ok to correct my post, but taking me -2 points for that? is not a solution to my issue, and more if I need some points to attach the images related to this problem. Thank you CBredlow !

编辑:我需要上传来解释这个问题的图片,但由于因此,它不那么友好的新用户,只要按照这个链接,查看图片:

EDITED: I need to upload the pictures that explain this issue, but since SO its not so friendly to new users, just follow this link to see the images:

的http://forum.xda-developers.com/showpost.php?p=56553476&postcount=2

推荐答案

!解决了!

由于某些原因,API19编程纯java动画犯规发挥得很好,绝对设置,如setX的()或塞蒂()。专家们可能会采取这个看看。 API19 preffers与布局上的参数侧边工作。

For some reason, API19 programmatically pure java animations doesnt play very well with absolut settings, like setX() or setY(). Experts may take a look on this. API19 preffers to work with margins on the layout parameter side.

下面的过程,适用的到Android 4.4.2。中五言,它适用于其他版本的向下和向上,但你必须改变你的思维方式。你必须把一个imagen画质编程方式使用布局参数,所以改变:

The following procedure, apply's to android 4.4.2. Of cource, it works on the others versions down and up, but you must change your way of thinking. You must place a imagen programmatically using layout parameters, so change:

iv.setX(50);
iv.setY(0);

lparam.setMargins(50, 0, 0, 0);
iv.setLayoutParams(lparam);
iv.requestLayout();

您也可以使用(对于API> = 17)

you can also use (for API >=17)

lparam.setMarginStart(50); // for x pos
lparam.setMarginEnd(0);  // for y pos

您必须调用requestLayout(),以确保布局上的新变化,将增加视图到父(佛罗里达州)时,应COMMITED。

You must call "requestLayout()" to ensure that the new changes on the layout, will be commited when adding the view to the parent (fl).

Finnally,错误,我用的LayoutParams,而不是FrameLayout.LayoutParams。这没有什么需要做的这个问题,并没有影响到它,而是把它定义正确的方式,使改变:

Finnally, by mistake, I use "LayoutParams" instead of "FrameLayout.LayoutParams". This nothing have to do with the issue and was not affecting it, but is the correct way to define it so change:

LayoutParams lparam = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

FrameLayout.LayoutParams lparam = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);

完整的工作$ C $下任何API是:

The complete working code for any API is:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Common common = new Common(this, this);
    FrameLayout fl = new FrameLayout(this);
    ImageView iv = new ImageView(this);

    FrameLayout.LayoutParams flparam = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
    FrameLayout.LayoutParams lparam = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);

    iv.setImageBitmap(common.newImage("100x100.png", ImageFormat.RGB565).getBitmap());
    lparam.setMarginStart(50);
    lparam.setMarginEnd(0);
    iv.setLayoutParams(lparam);
    iv.requestLayout();

    fl.addView(iv);
    this.setContentView(fl, flparam);

    AlphaAnimation animation = new AlphaAnimation(0, 1);
    animation.setDuration(3000);
    iv.setAnimation(animation);
    iv.startAnimation(animation);
}