4

我有一个 FrameLayout,其中包含一些图像视图和一个 EditText。我将此布局保存为内存中的图像(外部)。第一次我在 imageviews 中设置图像时一切正常,即正在保存确切的图像(与在屏幕上显示相同)但是在第一次保存后,如果我更改任何内容(文本、图像),它会在屏幕上正确显示但已保存图像它显示较早的图像(第一张图像)。

布局的 XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
<FrameLayout 
    android:id="@+id/imageWithoutFrame"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:layout_centerInParent="true" >

    <ImageView
        android:id="@+id/withoutFrame_background"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:src="@drawable/background" />

    <ImageView
        android:id="@+id/withoutFrame_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:adjustViewBounds="true"
        android:layout_gravity="center" />

    <EditText 
        android:id="@+id/withoutFrame_editableText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal|bottom"
        android:layout_marginBottom="30dip"
        android:hint="Write here"
        android:maxLength="60" />

</FrameLayout>
</RelativeLayout>

在位图中更改它的代码是:

Bitmap bm = null;
FrameLayout savedImage = null;
savedImage = (FrameLayout)findViewById(R.id.imageWithoutFrame);
savedImage.setDrawingCacheEnabled(true);
savedImage.buildDrawingCache();
bm = savedImage.getDrawingCache();

我用这个bm来保存。

感谢您的帮助。

4

1 回答 1

3

为了克服这个问题,我在保存图像后销毁了绘图缓存。

savedImage.destroyDrawingCache();
于 2012-05-11T05:00:14.080 回答