我有这样的代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
...
FrameLayout frameLayout = (FrameLayout)findViewById(R.id.rLayout_main);
frameLayout.setDrawingCacheEnabled(true);
frameLayout.buildDrawingCache(true);
Bitmap bitmap = frameLayout.getDrawingCache();
当布局activity_main中的id.rLayout_main时,位图非空。 但是当我将id.rLayout_main替换为id.layout_report时,它不在布局activity_main中,它在布局报告中。我改变了这样的代码:
FrameLayout viewGroup= new FrameLayout(context);
LayoutInflater inflaters = LayoutInflater.from(context);
View root = inflaters.inflate(R.layout.report,viewGroup, true);
FrameLayout frameLayout = (FrameLayout)root.findViewById(R.id.layout_report);
frameLayout.setDrawingCacheEnabled(true);
frameLayout.buildDrawingCache(true);
Bitmap bitmap = frameLayout.getDrawingCache();
这次,位图始终返回NULL。请帮助我!!!
答案 0 :(得分:0)
我认为问题在于您的观点已被夸大但尚未绘制。这就是位图为空的原因。如果你这样做会怎么样:
FrameLayout viewGroup = (FrameLayout)findViewById(R.id.rLayout_main);
LayoutInflater inflaters = LayoutInflater.from(context);
View root = inflaters.inflate(R.layout.report,viewGroup, true);
FrameLayout frameLayout = (FrameLayout)root.findViewById(R.id.layout_report);
frameLayout.setDrawingCacheEnabled(true);
frameLayout.buildDrawingCache(true);
Bitmap bitmap = frameLayout.getDrawingCache();