【问题标题】:Converting FrameLayout as Bitmap将 FrameLayout 转换为位图
【发布时间】:2012-05-10 12:42:07
【问题描述】:

我有一个 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 来保存。

感谢您的帮助。

【问题讨论】:

    标签: android android-framelayout


    【解决方案1】:

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

    savedImage.destroyDrawingCache();
    

    【讨论】:

    • 你的解决方案和view.setDrawingCacheEnabled(false)有什么不同;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-15
    • 1970-01-01
    • 1970-01-01
    • 2012-07-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多