0
所以我叫demo_text.xml转换外部XML布局为位图使用布局充气
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/screen">
<TextView
android:id="@+id/textToDisplay"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Hello World"
</FrameLayout>
我想这demo_text转换为位图下面的布局。这是我的创建:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View inflatedFrame = getLayoutInflater().inflate(R.layout.demo_text, null);
FrameLayout frameLayout = (FrameLayout) inflatedFrame.findViewById(R.id.screen) ;
frameLayout.setDrawingCacheEnabled(true);
frameLayout.buildDrawingCache();
Bitmap bm = frameLayout.getDrawingCache();
}
我想位图是整个布局,但位图总是返回null。
为什么你使用'FrameLayout'在你的活动视图的根源在哪里?你可以在'Fragment'中使用'FrameLayout'。无论如何,你可以尝试在'inflate'方法而不是'null'的第二个参数处传递'ViewGroup'根。 (不知道这是否工作) – lalosoft
重复https://stackoverflow.com/a/12406426/2700586 – Mani