安卓adjustViewBounds错误? [英] android adjustViewBounds bug?
问题描述
当我使用的Android版本:adjustViewBounds在我的ImageView XML =true,则它不起作用。如果我把setAdjustViewBounds(真正的);在我的ImageView的构造,它工作正常。有什么区别,或者这是一个错误?
< ImageView的
机器人:ID =@ + ID / PageViewMainImage
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:scaleType =矩阵
机器人:adjustViewBounds =真
机器人:能见度=隐形/>
在的ImageView
构造函数的操作顺序(<一href="https://github.com/android/platform_frameworks_base/blob/master/core/java/android/widget/ImageView.java">see来源此处)解析出来,并将从XML adjustViewBounds
属性之前它解析,并设置 scaleType
属性从XML。在 setAdjustViewBounds()
的方法(这被称为与你的XML属性值的构造函数)的一部分是设置 ScaleType
到 FIT_CENTER
当值为true。
所以,当您发布的XML被加载后, ScaleType
首先被设置为 FIT_CENTER
,然后重新设置以 MATRIX
之后,构造函数里面所有。你叫 setAdjustViewBounds()
在Java中,而是和现在最后的 ScaleType
将<$ C的例子比较一下$ C> FIT_CENTER 作为你的Java调用的XML属性后会发生被解析(实际上也就是说你的安卓scaleType =矩阵
属性忽略这种差别可能是你正在工作和不工作。
我不知道,如果谷歌将其称之为错误,因为它们只设置 ScaleType
来,他们认为你想要为方便preserve方面,但仍允许您修改。该视图的边界本身仍然会改变,因为属性名称指示,图像可能只是剪辑你没想到的方式。
该文档很可能是这个功能,虽然更清晰,让您可以在 http://b.android.com发送错误报告
心连心
When I use android:adjustViewBounds="true" in my imageView xml, it does not function. If I put setAdjustViewBounds(true); in the constructors of my ImageView, it works fine. What is the difference, or is this a bug?
<ImageView
android:id="@+id/PageViewMainImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="matrix"
android:adjustViewBounds="true"
android:visibility="invisible"/>
The order of operations in the ImageView
constructor (see source here) parses out and sets the adjustViewBounds
property from XML before it parses and sets the scaleType
attribute from XML. Part of the setAdjustViewBounds()
method (which is called by the constructor with your XML attribute value) is to set the ScaleType
to FIT_CENTER
when the value is true.
So when the XML you posted is loaded, the ScaleType
is first set to FIT_CENTER
and then re-set to MATRIX
afterwards, all inside the constructor. Compare this with your example of calling setAdjustViewBounds()
in Java instead, and now the final ScaleType
will be FIT_CENTER
as your Java call will happen after the XML attributes are parsed (effectively meaning that your android:scaleType="matrix"
attribute is ignored. That difference is likely what you are seeing between "works" and "doesn't work".
I'm not sure if Google would call it a bug, as they are only setting the ScaleType
to what they think you want as a convenience to preserve the aspect, but still allow you to modify this. The bounds of the view themselves will still change as the property name directs, the image just may clip in a way you didn't expect.
The docs could probably be more clear on this "feature" though, so you could file a bug report at http://b.android.com
HTH
这篇关于安卓adjustViewBounds错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!