【问题标题】:Android Dynamic Transparent Image OverlayAndroid 动态透明图片叠加
【发布时间】:2012-02-27 02:48:22
【问题描述】:

我需要在我希望用户看到的真实图像之上叠加一个透明图像。图像将存储在 SD 卡上。我已经看过很多关于这样做的教程,但它们似乎总是不知道如何显示这两个图像。或者,也许我只是想念它。无论如何,这是我的布局

<merge 
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/gallerylayout"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <ImageView
    android:id="@+id/visible_image"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
  />
  <ImageView
    android:id="@+id/colormap_overlay"
    android:background="#FF000000"      
    android:scaleType="fitXY"
    android:layout_alignTop="@id/visible_image"
    android:layout_alignBottom="@id/visible_image"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
  />
</merge>

这是我的代码:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ctx = getApplicationContext();
    setContentView(R.layout.imagepage);
    String image_overlay = Environment.getExternalStorageDirectory() + "/" + s(R.string.APP_NAME) + "/overlay.jpg";
    String visible_image = Environment.getExternalStorageDirectory() + "/" + s(R.string.APP_NAME) + "/visible.jpg";

    ImageView image = (ImageView)findViewById(R.id.visible_image);
    BitmapFactory.Options options = new BitmapFactory.Options();
    Bitmap bm = BitmapFactory.decodeFile(visible_image, options);
    image.setImageBitmap(bm);

    ImageView overlayimage = (ImageView)findViewById(R.id.colormap_overlay);
    Bitmap bm2 = BitmapFactory.decodeFile(image_overlay);
    overlayimage.setAlpha(0);
    overlayimage.setImageBitmap(bm2);
    }

我很确定我的错误在我的代码中。

编辑1 我做了一些测试,看起来 xml 布局还可以。我可以单独显示可见图像,但是当我显示第二张图像(透明图像)时,我得到的只是一个空的全黑显示。

要显示第二张图像,我是否只需再次调用 setImageBitmap() ?我开始认为我需要做点别的事情。

【问题讨论】:

  • 在Edit1中添加了一些附加信息
  • 将布局和图像重新标记到其特定标签 android-layout 和 android-images
  • 合并标签在我的 xml 中根本不起作用,应用程序将无法启动。我在这里找到了答案stackoverflow.com/questions/14718028/…

标签: android android-layout transparency android-image


【解决方案1】:

我想通了。我需要从布局 xml 中删除 android:background="#FF000000"。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-07
    • 2010-10-01
    • 1970-01-01
    • 2015-04-21
    相关资源
    最近更新 更多