【问题标题】:Why is my ImageView with alpha invisible when placed over opaque ImageView?为什么我的带有 alpha 的 ImageView 在放置在不透明的 ImageView 上时不可见?
【发布时间】:2016-08-22 09:43:59
【问题描述】:

在我的 Android 应用程序中,我会将一张具有一定透明度的图像放在具有最大不透明度的背景上。为了尝试这个,我尝试创建一个相对布局,具有背景图像视图(创建背景,具有完全不透明度,alpha = 1),并在此之上另一个图像视图,具有低不透明度值(alpha)。而且,在相同的相对布局中,还有一个带有一些指示的文本视图。

很奇怪!在我的 Android 模拟器上,一切正常。但是在不止一个真实设备中,我可以完美地看到背景图像视图和 TextView,但第二个图像视图(图像不透明度低的那个)完全不可见!为什么?谢谢,我复制下我的代码。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:layout_weight="1" android:id="@+id/controlImageView">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/controlImageViewBack"
        android:focusableInTouchMode="false"
        android:paddingTop="10dp"
        android:paddingBottom="10dp"
        android:background="@drawable/bck_main"
        android:alpha="1"
        android:layout_weight="1"
        android:contentDescription="@string/desc_img_control_background"/>

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/controlImageViewPicture"
            android:scaleType="fitStart"
            android:src="@drawable/ctrl_bck"
            android:focusableInTouchMode="false"
            android:paddingTop="10dp"
            android:alpha="0.5"
            android:paddingBottom="10dp"
            android:layout_alignTop="@id/controlImageViewBack"
            android:contentDescription="@string/desc_img_control_picture"/>

        <TextView android:id="@+id/controlMessageText" android:layout_width="match_parent"
            android:layout_height="match_parent" android:layout_alignTop="@id/controlImageViewBack"
            android:textSize="@dimen/board_text_size"
            android:textColor="@color/colorButtonText"
            android:textAlignment="center" android:gravity="center"
            android:text="@string/mod_control_nomessage"/>

    </RelativeLayout>

【问题讨论】:

    标签: android android-imageview transparency opacity


    【解决方案1】:

    解决了!来自日志:

    05-01 12:46:12.288 24904-24904/com.mycompany.myapp W/OpenGLRenderer:位图太大,无法上传到纹理中(840x2524,最大值=2048x2048)。

    很奇怪,但我第一次看到在某些图形元素中无法插入太大的图像。

    【讨论】:

      【解决方案2】:

      首先, weight 和 layoutOrientation 对相对布局没有任何影响!

      代码在我的 Nexus 5X 上运行!

      你用的是什么真机?

      【讨论】:

      • 感谢您的快速回答!三星 Galaxy Nexus,Android 4.3(与应用程序 4.0 兼容的最低版本)。在此设备上,背景图像视图和文本视图可见,但图片图像视图不可见(alpha 值较低)。
      • 也许你应该在设置内容视图后为图像视图记录以下值:宽度/高度/Alpha值
      • 您能给我们看看我们可以帮助您的日志操作系统吗?
      • 已经完成,已经解决了。请看我之前的回答。谢谢!
      猜你喜欢
      • 1970-01-01
      • 2018-03-27
      • 2014-01-19
      • 1970-01-01
      • 2010-12-02
      • 2014-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多