如何打开在Android的屏幕特定区域的PDF文件 [英] How to open pdf file on particular area of the screen in Android
问题描述
我有哪些需求,我的屏幕标题标签上出现,底部
屏幕的一个按钮是存在的。我想说明这个标签之间的PDF文件
和按钮如何,我会实现这个?当我试图打开PDF文件它的充分
屏幕空间。
文件文件=新的文件(getFilesDir(),mypdf.pdf);
尝试{
FIS =新的FileInputStream(文件);
}赶上(FileNotFoundException异常E1){
// TODO自动生成catch块
e1.printStackTrace();
}
//System.out.println(file.exists()+!!);
// InputStream的时间= resource.openStream();
ByteArrayOutputStream BOS =新ByteArrayOutputStream();
字节[] buf中=新的字节[1024];
尝试{
为(中间体readNum;(readNum = fis.read(BUF))= -1;!){
bos.write(BUF,0,readNum); //毫无疑问,这里是0
//写len个字节从指定的字节数组偏移量off开始该字节数组输出流。
的System.out.println(读+ readNum +字节);
}
}赶上(IOException异常前){
ex.printStackTrace();
}
字节[]字节= bos.toByteArray(); //下面是不同的部分
文件someFile =新的文件(java2.pdf);
尝试{
FOS的FileOutputStream =新的FileOutputStream(someFile);
fos.write(字节);
fos.flush();
fos.close();
}赶上(FileNotFoundException异常五){
// TODO自动生成catch块
e.printStackTrace();
}赶上(IOException异常五){
// TODO自动生成catch块
e.printStackTrace();
}
意向意图=新意图(Intent.ACTION_VIEW);
intent.setDataAndType(
Uri.parse(文件://+ getFilesDir()+/java2.pdf),
应用程序/ PDF格式); startActivity(意向);
我没有尝试,但你应该尝试使用片段在Ativity要显示的PDF。从最初的网站:
一个片段重新presents行为或在活动用户界面的一部分。您可以在一个单一的活动结合多个片段来构建一个多窗格界面和重用在多个活动片段。
块引用>使用按钮和标题并在其上打开PDF之间的一个片段。也许这会帮助你。
I have requirement at which, on my screen header label is there and on the bottom of the screen one button is there. I want to show PDFs file between this label and button how I will implement this? When I am trying to open PDFs It's taking full screen space.
File file = new File(getFilesDir(), "mypdf.pdf"); try { fis = new FileInputStream(file); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //System.out.println(file.exists() + "!!"); //InputStream in = resource.openStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; try { for (int readNum; (readNum = fis.read(buf)) != -1;) { bos.write(buf, 0, readNum); //no doubt here is 0 //Writes len bytes from the specified byte array starting at offset off to this byte array output stream. System.out.println("read " + readNum + " bytes,"); } } catch (IOException ex) { ex.printStackTrace(); } byte[] bytes = bos.toByteArray(); //below is the different part File someFile = new File("java2.pdf"); try { FileOutputStream fos = new FileOutputStream(someFile); fos.write(bytes); fos.flush(); fos.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType( Uri.parse("file://" + getFilesDir() + "/java2.pdf"), "application/pdf"); startActivity(intent);
解决方案I didn't try, but you should try to use Fragments in the Ativity you want to show the PDF. From the original site:
A Fragment represents a behavior or a portion of user interface in an Activity. You can combine multiple fragments in a single activity to build a multi-pane UI and reuse a fragments in multiple activities.
Use a single fragment between the button and the header and open PDF on it. Maybe it will help you
这篇关于如何打开在Android的屏幕特定区域的PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!