Android PDF scrollview single continuous page - java

In xcode I can display a PDF as a single continuous page, with the PDF width being equal to screen width and then the vertical scroll being the height of PDF for said width. No problems
Currently converting same app to Android and having some difficulty implementing same PDF view
Basically I have a PDF page that is very long (single page). I don't want to swipe between pages, but instead like in my iOS app, have the PDF document fill the Android screen width wise, and then scroll vertically to show rest of PDF
I'm using com.github.barteksc.pdfviewer.PDFView to render my PDF
In my xml for the activity I have:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
android:fillViewport="true">
tools:context=".ProfileActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.github.barteksc.pdfviewer.PDFView
android:id="#+id/pdfView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</ScrollView>
I've tried changing the layout_height to "wrap_content" for scrollView, Linear and pdf, as that would seem appropriate, but whenever I do this I get a blank screen. It seems that doing so resulting in no height attribute so the view collapses completely
I get:
What I want:
Would really appreciate any further help, this is really my only sticking point. I wish android had PDFKit (similar) as I found that quite easy to use and implement

Well there is an answer!
I had to 'upgrade' to the latest version: 3.1.0-beta.1 and use the:
.pageFitPolicy(FitPolicy.WIDTH)
Combined with my XML:
<ScrollView 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"
android:fillViewport="true">
tools:context=".AboutActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical">
<com.github.barteksc.pdfviewer.PDFView
android:id="#+id/pdfView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</ScrollView>
Worked perfectly. I hope this helps others

Related

backgroundTint in XML does not change color of BottomActionBar, even with min API >= 21

I'm trying to set up a basic BottomActionBar with an attached FloatingActionButton. Currently, everything seems to work, aside from the background of the bar. If I use android:background="some_background_color", the bar is filled in with the desired color.
The problem is that I want my FAB to be cradled, and this approach seems to be incompatible with fabCradleMargin and fabCradleRoundedCornerRadius, as the background bar is unaffected by modifying these values.
All tutorials indicate that app:backgroundTint="some_background_color" is the way to go, but my action bar remains unaffected by this. I've set my API to >= 21, so as far as I know, there are no issues there.
My XML file:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".MainActivity">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent">
<com.google.android.material.bottomappbar.BottomAppBar
android:id="#+id/bottom_app_bar"
style="#style/Widget.MaterialComponents.BottomAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:backgroundTint="#color/colorPrimary"
app:fabAlignmentMode="center"
app:fabAttached="true"
app:fabCradleMargin="10dp"
app:fabCradleRoundedCornerRadius="10dp" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_add_white_24dp"
app:layout_anchor="#+id/bottom_app_bar"
app:layout_anchorGravity="center_horizontal"
app:fabSize="normal"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
The backgroundTint has no effect on the bar; it remains completely white.
Sorry if this is an elementary question; I'm quite new to Android and have spent quite a while searching for a solution to no avail.
I tested your code
it shows an error for BottomAppBar so I findout this code app:fabAttached="true" is Undefined...
remove it and it will work perfectly.
Goodluck.

OSMdroid how to add watermark

I'm creating an free Android application and I'm using OpenStreetMap (OSMdroid library). I have a question. On the webpage: https://www.openstreetmap.org/copyright
I have read, that I should put a text in the corner of map activity (#OpenStreetMap contributors).
How to do this?
I'd like my app to be comply with the OSM license.
Regards
There is a built in copyright overlay for displaying the notice based on the current tile source.
Edit, sample code is below
//Copyright overlay
mCopyrightOverlay = new CopyrightOverlay(context);
mMapView.getOverlays().add(this.mCopyrightOverlay);
Basically, whatever the current tile source is, the text overlay will be drawn.
When you have your layout file simply add a TextView with "#OpenStreetMap contributors" to it. (I recommend to use a RelativeLayout)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<org.osmdroid.views.MapView android:id="#+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:text="OpenStreetMap Contributors" />
</RelativeLayout>
I saw in other apps that on startup they all show this and a few seconds later it is fading out so you can use a delayed animation for that.
textView.animate().setStartDelay(3000).alpha(0).setDuration(1000).start();

Android RelativeLayout stretch background

all.
this is my layout code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#mipmap/backgroung"
tools:context=".MainScreen">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30pt"
android:text="#string/level1"
android:onClick="#string/level1"
android:id="#+id/level1"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="60pt"
android:text="#string/level2"
android:id="#+id/level2"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="90pt"
android:text="#string/level3"
android:id="#+id/level3"/>
It look like is:
I want that the punch photo will stretch all over the white background.
Thanks for helpers!
Better to use a 9patch image here. In which the punch area can be constant and the image can stretch with the blue region. That way you won't face the issue of the image being blurred because of stretching. You can find some good examples of how to create a 9patch from youtube. here's a sample.
I got it,
when add new image asset it resize the image and crop to with white borders.
Need to hard copy-paste the entire photo to the drawable folder.
In your RelativeLayout, do you see those android:paddingTop and bottom/left/right? Remove all those or change to ="0dp".
Move your image into <ImageView/> before the buttons.
And use android:scaleType="fitXY"
Oh, make sure your pic does not have any whitespace border.

Android: Adding Image to Master Detail Flow, scrolling text

I'm working on a information orientated app using the master/detail flow and so far, so good. I would like to add images to the TextView, but it's formatted differently then what I've experienced in the past and I'm lost. from my understanding of what I've read while searching is that the scrolling text is "newer" when generating the Master/detail activity, therefore I haven't found any information on this specific issue. I would also like to pass the images in using the content activity, so it would be-
addItem(new Item(ID,Name,Detail,Image1,Image2));
what the detail XML file looks like
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/bobblehead_detail"
style="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:textIsSelectable="true"
tools:context="com.example.johnson.fallout4bobbleheadlocations.BobbleheadDetailFragment" />
I tried adding ImageView's under it, but I received errors.
tl;dr I would like to add 2 images under the scrolling TextView.
I am not sure if I clearly understand what you mean but looking at your xml it seems to me that you need to add a layout (either relative or linear) to your xml file and then add a textview and two imageviews (or whatever you want) into that layout.
Something like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp" tools:context="com.example.somefragment">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/some_id2"
android:text="Here is your text"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/some_id"
android:src="#drawable/image1"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/some_id3"
android:src="#drawable/image2"/>
</RelativeLayout>

Can't get imageview to sit flush with the top of the screen

I'm trying to place an image view at the top of the screen, but it has some type of margin above and below it. So I tried adjustViewBounds = true, and it worked but then it wouldn't reach the sides of the screen. I just want it to be flush with the top of the screen, and reach the sides. Any suggestions?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="match_parent"
tools:context="${packageName}.${activityClass}"
android:orientation="vertical" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/title_bar"/>
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="200dp" >
<LinearLayout
android:id="#+id/goals"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#android:color/black" >
</RelativeLayout>
If it is just colored title bar - then it is make sense to use just View for example and set background property to needed color. If You have custom image for that and can not adjust it with default ImageView properties - then You can make 9Patch from your image and use it as a background also (in 9patch you decide by yourself how to scratch image and where to place content). You can find 9patch tool in android SDK. More info about 9patch:
http://developer.android.com/reference/android/graphics/NinePatch.html
I had this same problem. What I ended up doing was using a negative margin on the top of the ImageView like so:
android:layout_marginTop="-4dp"
You may have to play around to find the optimal number of dp for you. Hope this helps.

Categories

Resources