gpt4 book ai didi

android - ImageView 在某些设备上显示 Drawable 半透明/透明

转载 作者:行者123 更新时间:2023-11-29 00:17:36 26 4
gpt4 key购买 nike

我们有一个 TextView,其中包含来自应用程序资源的可绘制左侧和可绘制右侧。在某些设备上,例如

  • 运行 Android 4.1.2 的索尼 Xperia L,
  • 三星 Galaxy Young 或
  • 三星 Galaxy SII

我们遇到了一个奇怪的问题。可绘制对象将显示为半透明/透明。在其他设备上,例如

  • 三星 Galaxy S4 (4.4.2) 或
  • 宏达一号 (4.0.3)

可绘制对象将正确显示。

这是布局定义的截图:

        <TextView
android:id="@+id/button_current_warnings"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="3dp"
android:gravity="center_vertical"
android:background="@drawable/selector_classic_list_item"
android:layout_gravity="center_vertical"
android:drawablePadding="8dp"
android:drawableLeft="@drawable/ic_classic_current_warning_white"
android:drawableRight="@drawable/ic_classic_row_arrow"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:maxLines="2"
android:ellipsize="end"
android:text="@string/current_warnings"
android:textSize="?attr/warningGermanyBoxTextSize"
android:textColor="?attr/itemFavoriteTitleTextColor"/>

在 HTC One V 设备上,这种布局看起来很漂亮:

enter image description here

在 Sony Xperia L 上,由于 imageview 可绘制对象的透明度,布局被破坏了。两个可绘制对象都只显示了一点点:

enter image description here

此外,如果我们将 drawable 更改为不同的,结果在两种设备上都很好:

宏达电:

enter image description here

索尼:

enter image description here

另外,我附上了我当前测试使用的两个可绘制对象(它们都是白色的,因此您在这里看不到任何东西):

错误显示的绘图:

enter image description here

正确显示可绘制对象:

enter image description here

有没有人遇到同样的问题或对我们有任何提示?

更新:在我的代码中,我只在这个 TextView 上设置了一个 ClickListener:

     buttonGermany = returnView.findViewById(R.id.button_current_warnings);
buttonGermany.setVisibility(View.VISIBLE);
buttonGermany.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Do something
}
});

最佳答案

我只在 Android 4.1.2 (Jelly Bean) 设备上遇到过这个问题。图标半透明显示的问题与 4.1.2 中的可绘制对象缓存有关。就我而言,我也在可绘制选择器中使用了错误的 ic_classic_current_warning_white-drawable:

<selector xmlns:android="schemas.android.com/apk/res/android"; android:exitFadeDuration="@android:integer/config_mediumAnimTime"> 
<item android:state_pressed="false" android:state_focused="true" android:drawable="@drawable/ic_classic_current_warning_white"/>
<item android:state_pressed="true" android:drawable="@drawable/ic_classic_current_warning_white"/>
<item android:drawable="@drawable/ic_classic_current_warning_black"/>
</selector>

这个选择器在之前的 Activity 中用在了一个按钮上。如果我触摸这个按钮,就会出现上面的 View 。通过使用 android:exitFadeDuration ic_classic_current_warning_white-drawable 在触摸我的按钮后淡出。但是,当新 Activity 打开时,可绘制缓存似乎持有对 ic_classic_current_warning_white-drawable 的引用,其 alpha 值低于 100%。如果我在下一个 View 中再次使用这个可绘制对象,它不会以 100% alpha 显示,而是以离开上一个 Activity 时的 alpha 值显示。

我目前的解决方案是简单地复制可绘制的 ic_classic_current_warning_white。一个将用于选择器。另一个副本将用于“静态”目的。

关于android - ImageView 在某些设备上显示 Drawable 半透明/透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25543593/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com