android 将 FrameLayout 转换为 Drawable

标签 android bitmap android-framelayout

我的 LinearLayout 中有这个 FrameLayout:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/desktopsFramelayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="none"
        android:src="@drawable/accept" />

</FrameLayout>

然后在代码中,我尝试像这样在 Drawable 中转换它:

FrameLayout desktopFrameLayout = (FrameLayout)findViewById(R.id.desktopsFramelayout);

        desktopFrameLayout.setDrawingCacheEnabled(true);
        desktopFrameLayout.buildDrawingCache();     
        Bitmap bitmap = desktopFrameLayout.getDrawingCache();

位图null,为什么???

最佳答案

查看此链接并阅读 nininho 的回答: Android View.getDrawingCache returns null, only null

我认为它返回 null 因为你的 View 有维度 (0,0)

关于android 将 FrameLayout 转换为 Drawable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15223012/

相关文章:

java - 在位图上使用 Matrix.polyToPoly() 时,有没有办法不拉伸(stretch)位图?

android - 如何以编程方式在 FrameLayout 中的另一个 LinearLayout 下添加 LinearLayout?

Android:如何实现这样的布局?

androidx requestPermissionLauncher 导致 java.lang.IllegalArgumentException : Can only use lower 16 bits for requestCode

android - Gradle 在 UI 中标记错误,但构建得很好

c# - 分别获取位图图像中黑白像素的总数

android - 为什么会为此位图抛出空指针异常?

android - 设置framelayout边距及其子元素的宽度、高度和位置

android - 如何在主屏幕小部件中包含 CardView

android - 什么代码可以禁用android(4.4)设备的耳机插孔