【发布时间】:2015-02-09 09:30:06
【问题描述】:
这个问题可能看起来微不足道,被问了很多次,但我找不到适合我的答案。
当我按下按钮时,我有一个ImageView 和GLSurfaceView 绘制在ImageView 之上。
对于我的ImageView,我传递了一个Bitmap 并将其缩小以避免OutOfMemoryError 异常。我的ImageView 与我的 UI 中的其他元素对齐,因此它会拉伸图像以填充宽度/高度(这就是我想要的)。
当我从 ImageView 更改为 GLSurfaceView 时,我的图像周围出现黑色区域,这些区域在我的 ImageView 中是透明的,因为 GLSurfaceView 在 UI 中打了一个洞,并且与通常绘制背景的元素的工作方式不同我的图像变成黑色,我不需要它,因为我有自定义背景。
我想出了一个解决方案,以编程方式将LayoutParams 设置为GLSurfaceView,并使用Bitmap 的宽度和高度,但最终得到的图像更小。我需要显示图像的确切宽度和高度 - 而不是 ImageView,因为它具有透明区域。
PS:我不是 OpenGL 专家,如果您有适用于 OpenGL 的解决方案,请分享。
一)
_______________
| |
| |
|---------------| <-
| transparent |
|---------------| <- Entire
| | ImageView
| Image | need
| | only this
|---------------| <-
| transparent |
|---------------| <-
| |
---------------
b)
_______________
| |
| |
|---------------| <-
| black |
|---------------|
| |
| Image | GLSurfaceView
| |
|---------------|
| black |
|---------------| <-
| |
---------------
我的ImageView 和GLSurfaceView:
<android.opengl.GLSurfaceView
android:id="@+id/glsvImageHolder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/horScrollImage"
android:layout_marginBottom="5dp"
android:layout_marginTop="50dp"
android:visibility="invisible" />
<ImageView
android:id="@+id/ivImageHolder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/horScrollImage"
android:layout_marginBottom="5dp"
android:layout_marginTop="50dp"
android:visibility="visible" />
【问题讨论】:
-
位图本身是否包含顶部和底部透明区域?
-
不,位图不包含透明区域。
标签: android imageview width glsurfaceview layoutparams