AndroidプリントフレームDemo
6506 ワード
Android API , Android 。
http://www.kuqin.com/shuoit/20140625/340810.html , Demo,
/** * * * @description: * @author ldm * @date 2016-4-28 9:54:17 */
public class MainActivity extends Activity implements OnClickListener {
private Button bitmap_btn;
private Button layout_btn;
private Button html_btn;
private Button off_screen_btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initViews();
}
private void initViews() {
this.bitmap_btn = (Button) findViewById(R.id.bitmap_btn);
this.layout_btn = (Button) findViewById(R.id.layout_btn);
this.html_btn = (Button) findViewById(R.id.html_btn);
this.off_screen_btn = (Button) findViewById(R.id.off_screen_btn);
this.bitmap_btn.setOnClickListener(this);
this.layout_btn.setOnClickListener(this);
this.html_btn.setOnClickListener(this);
this.off_screen_btn.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.bitmap_btn:
startIntent(PrintBitmapActivity.class);
break;
case R.id.layout_btn:
startIntent(PrintLyaoutActivity.class);
break;
case R.id.html_btn:
startIntent(PrintHtmlActivity.class);
break;
case R.id.off_screen_btn:
startIntent(PrintHtmlOffScreenActivity.class);
break;
}
}
private void startIntent(Class<?> tagert) {
Intent in = new Intent(this, tagert);
startActivity(in);
}
}
/** * Android * * @description * @author ldm * @date 2016-4-27 */
public class PrintBitmapActivity extends Activity {
private ImageView mImageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.print_bitmap);
mImageView = (ImageView) findViewById(R.id.image);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.print_custom_content, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.menu_print) {
print();
return true;
}
return super.onOptionsItemSelected(item);
}
private void print() {
// // bitmap 。
PrintHelper printHelper = new PrintHelper(this);
/** * PrintHelper setScaleMode() , * SCALE_MODE_FIT: , * SCALE_MODE_FILL: , */
printHelper.setScaleMode(PrintHelper.SCALE_MODE_FIT);
// ImageView
Bitmap bitmap = ((BitmapDrawable) mImageView.getDrawable()).getBitmap();
//
printHelper.printBitmap("Print Bitmap", bitmap);
}
}
二つの種類のコードだけを貼りました。Demoは住所をダウンロードします。http://download.csdn.net/detail/true100/9505015