compile 'com.github.barteksc:android-pdf-viewer:2.8.1'
|
3.main_activity.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context="com.arham.csdevbin.pdfdomo.MainActivity"> | |
<com.github.barteksc.pdfviewer.PDFView | |
android:id="@+id/pdfView" | |
android:layout_width="match_parent" | |
android:layout_height="500dp" | |
android:layout_marginTop="8dp"> | |
</com.github.barteksc.pdfviewer.PDFView> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_alignParentBottom="true" | |
android:orientation="horizontal" | |
android:weightSum="1"> | |
<Button | |
android:id="@+id/nextBtn" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_weight=".25" | |
android:onClick="nextPage" | |
android:text="Next" /> | |
<Button | |
android:id="@+id/prevBtn" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_alignParentBottom="true" | |
android:layout_weight=".25" | |
android:onClick="prevPage" | |
android:text="Prev" /> | |
<Button | |
android:id="@+id/button3" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_weight=".25" | |
android:onClick="zoomIn" | |
android:text="Zoom in" /> | |
<Button | |
android:id="@+id/button4" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_weight=".25" | |
android:onClick="zoomOut" | |
android:text="zoom out" /> | |
</LinearLayout> | |
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.arham.csdevbin.pdfdomo; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import com.github.barteksc.pdfviewer.PDFView; | |
public class MainActivity extends AppCompatActivity { | |
public PDFView pdfView; | |
public float zoomValue = 1; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
pdfView = (PDFView) findViewById(R.id.pdfView); | |
pdfView.fromAsset("kitab_at_tawheed.pdf") | |
// .spacing(10) | |
.enableSwipe(true) // allows to block changing pages using swipe | |
.swipeHorizontal(true) | |
.enableDoubletap(true) | |
.defaultPage(0) | |
.load(); | |
} | |
public void nextPage(View view) { | |
pdfView.jumpTo(pdfView.getCurrentPage() + 1, true); | |
} | |
public void prevPage(View view) { | |
pdfView.jumpTo(pdfView.getCurrentPage() - 1, true); | |
} | |
public void zoomIn(View view) { | |
++zoomValue; | |
pdfView.zoomTo(zoomValue); | |
pdfView.loadPages(); | |
} | |
public void zoomOut(View view) { | |
if (zoomValue != 1) { | |
--zoomValue; | |
pdfView.zoomTo(zoomValue); | |
pdfView.loadPages(); | |
} | |
} | |
} |
Comments :
Post a Comment