嗨,我试着编写一个截图的功能.
我找到了一个代码,通过按钮clicklistner完美地完成它,但当我删除按钮clicklistner并尝试在oncreate中截取我获得的位图是空的.
为什么会这样?
布局:
@H_502_12@
活动:
public class MainActivity extends Activity {
LinearLayout L1;
ImageView image;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
L1 = (LinearLayout) findViewById(R.id.LinearLayout01);
Button but = (Button) findViewById(R.id.munchscreen);
but.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
View v1 = L1.getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bm = v1.getDrawingCache();
BitmapDrawable bitmapDrawable = new BitmapDrawable(bm);
image = (ImageView) findViewById(R.id.screenshots);
image.setBackgroundDrawable(bitmapDrawable);
}
});
}
}
@H_502_12@
最佳答案