为什么我的带 alpha 的 ImageView 放在不透明的 ImageView 上时不可见?
Why is my ImageView with alpha invisible when placed over opaque ImageView?
在我的 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>
首先,weight 和 layoutOrientation 对 Relative Layout 没有任何影响!
代码适用于我的 Nexus 5X!
你用的是什么真实设备?
已解决!来自日志:
05-01 12:46:12.288 24904-24904/com.mycompany.myapp W/OpenGLRenderer: Bitmap too large to be uploaded into a texture (840x2524, max=2048x2048).
很奇怪,但是我第一次看到在某些图形元素中无法插入太大的图像。
在我的 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>
首先,weight 和 layoutOrientation 对 Relative Layout 没有任何影响!
代码适用于我的 Nexus 5X!
你用的是什么真实设备?
已解决!来自日志:
05-01 12:46:12.288 24904-24904/com.mycompany.myapp W/OpenGLRenderer: Bitmap too large to be uploaded into a texture (840x2524, max=2048x2048).
很奇怪,但是我第一次看到在某些图形元素中无法插入太大的图像。