Android Xml drawable在放大时被像素化
我正在使用此图像:Android Xml drawable在放大时被像素化,android,xml,drawable,Android,Xml,Drawable,我正在使用此图像: <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="32dp" android:height="39dp" android:viewportWidth="32" android:viewportHeight="39"> <path android:pathData="M15.8575,6.5831L15.8575,1.0031C15.8575,
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="39dp"
android:viewportWidth="32"
android:viewportHeight="39">
<path
android:pathData="M15.8575,6.5831L15.8575,1.0031C15.8575,0.1031 14.7775,-0.3369 14.1575,0.3031L6.5575,7.8831C6.1575,8.2831 6.1575,8.9031 6.5575,9.3031L14.1375,16.8831C14.7775,17.5031 15.8575,17.0631 15.8575,16.1631L15.8575,10.5831C23.3175,10.5831 29.2175,17.4231 27.5775,25.1631C26.6375,29.7031 22.9575,33.3631 18.4375,34.3031C11.2975,35.8031 4.9375,30.9031 3.9775,24.2831C3.8375,23.3231 2.9975,22.5831 2.0175,22.5831C0.8175,22.5831 -0.1425,23.6431 0.0175,24.8431C1.2575,33.6231 9.6175,40.1231 19.0775,38.2831C25.3175,37.0631 30.3375,32.0431 31.5575,25.8031C33.5375,15.5431 25.7375,6.5831 15.8575,6.5831Z"
android:strokeWidth="1"
android:fillColor="#fff"
android:fillType="evenOdd"
android:strokeColor="#00000000"/>
<path
android:pathData="M-34,-30h100v100h-100z"
android:strokeWidth="1"
android:fillType="evenOdd"
android:strokeColor="#00000000"/>
</vector>
我使用的是焦点导航,因此在按钮的onFocusChanged
中,我使用此扩展将其放大:
fun View.enlarge(turnOn: Boolean) {
if (turnOn) {
translationZ = 1f
scaleX = 1.2f
scaleY = 1.2f
} else {
translationZ = 0f
scaleX = 1.0f
scaleY = 1.0f
}
}
它工作得很好,但是在我放大它之后,即使它是xml,它还是被像素化了。图像质量下降。是什么导致了这种情况?我如何避免这种情况并保持图像良好
编辑:根据下面的答案尝试了不同的方法,但未成功
override fun onFocusChanged(gainFocus: Boolean, direction: Int, previouslyFocusedRect: Rect?) {
if (gainFocus) {
imageView.layoutParams.height = 60
imageView.layoutParams.width = 60
} else {
imageView.layoutParams.height = 50
imageView.layoutParams.width = 50
}
}
或
这两种方法都不起作用。这一次,图标变小时会被像素化
VectorDrawable还有什么问题?使用缩放X/Y来放大视图会使它们失去质量,而不是增加宽度和高度,因为使用VectorDrawable可以正确缩放,要在代码中实现这一点,请使用视图的布局参数。。。但请注意,按钮的可绘制性并不随按钮缩放,因此您应该尝试其他功能,如图像按钮或按钮旁边带有可绘制性的线性布局。很有意义。谢谢。不幸的是,仍然没有工作。正在尝试通过drawable.setBounds()或imageview.layoutParams进行放大,但它们都不起作用。图像仍然是像素化的,但这次当它返回到较小的状态时,它是像素化的。更新问题。
override fun onFocusChanged(gainFocus: Boolean, direction: Int, previouslyFocusedRect: Rect?) {
if (gainFocus) {
imageView.layoutParams.height = 60
imageView.layoutParams.width = 60
} else {
imageView.layoutParams.height = 50
imageView.layoutParams.width = 50
}
}
override fun onFocusChanged(gainFocus: Boolean, direction: Int, previouslyFocusedRect: Rect?) {
if (gainFocus) {
imageView.drawable.setBounds(0,0,60,60)
} else {
imageView.drawable.setBounds(0,0,50,50)
}
}