First let me say that I'm very new to android development (although I have a good understanding of the basics of java), and I am building a magazine reader app for a campus publication I work for.
I want to display each article using a ViewPager widget. I'm going to build a java program which enables the magazine editor to post articles in .txt format onto a server, along with images associated with each, and have the android app periodically download these articles to a local folder.
I'm a little confused about how to construct the views for each ViewPager from the text files. Somehow my logic needs to determine the size of the screen running the app, in order to know how many words can fit on each screen.
Is this right, or am I fundamentally misunderstanding ViewPager somehow? If so, how might I structure the program to configure the views dynamically based on the txt + images given to it?
From what I understand, each page will contain as much of the article as possible, and when the user selects the article they will be able to see the entire thing. Something like this, but so it fills up the entire screen?
If this is the case, you have two options here:
Just ellipsize the textview so that it ends with a "..." at the end. Probably the preferred solution.
Resize the TextView to fit all your text (Auto Scale TextView Text to Fit within Bounds).
EDIT:
Here's a different interpretation of your question.
From what I understand, you're trying to have something like an eBook reader with an undefined number of pages; kind of what Flipboard does:
Basically, once all the text fills in the entire area you want to have it continue to the next page.
The easiest way to do this, if you do not need native performance, would be to just use a WebView, split the text across several columns, and have only one column be visible at a time.
However, it is certainly possible to calculate how tall the entire text would be and then split it up accordingly; i.e. Pagination in Android TextView
It seems similar questions have been asked and addressed: Splitting a TextView into multiple TextViews relative to screen height (see the accepted answer).
Related
Now that it's 2022 and Android tablets (and their cousins, foldables) are getting more prevalent, I got my interest ramped up in building a better tablet version of one of my apps. Coming from iOS, there is a useful layout feature that one can use when designing tablet UIs called "readable content guide". Apple describes it as follows:
This layout guide defines an area that can easily be read without forcing users to move their head to track the lines. The readable content area follows the following rules:
The readable content guide never extends beyond the view’s layout margin guide.
The readable content guide is vertically centered inside the layout margin guide.
The readable content guide’s width is equal to or less than the readable width defined for the current dynamic text size.
A picture is worth a thousand words. To the right is some text aligned to the readable content guide (the left version just spans the width of the main view):
Looks great when reading long-form content, doesn't it? Thus, my question:
is there a standardized version (that is, without me having to code one myself) of a feature similar to this on Android?
Now that version 12L is out, I thought it would incorporate something like this, especially with Google promoting Jetpack Compose (and other new UI extensions) as a faster and easier way to build UIs.
If you know what a comfortable width is you can use android:maxWidth="yourWidth" to limit the width of your textview to what you want
Say you've a list of Strings. The number of Strings varies. Is there a way to randomly display these strings like in an Apple presentation when they show a bunch of features in a slide. See link for an example.
http://www.technobuffalo.com/2011/06/10/iphone-5-feature-hinted-at-in-ios-5-wwdc-presentation/
So, text is randomly scattered but never overlaps. Spacing is pretty even. Some text is dim, some is bolder, big, small, etc. I couldn't find the 'name' of this effect (or these multiple combined effects) if there even is one?
I assume they do it manually in a slide of course, but I was wondering if there was a known way of doing this programmatically.
Any help would be much appreciated!
Good day, i am developing an android app which generates comic like albums, i need to fit this comic to any screen width but i have trouble doing it coz of the layouts, its very odd and doesn't seem to be aligned with one another, here :
those boxe are composed of FrameLayouts which contains and ImageView (back), the frame which is a PNG (middle) and a TextView on top of the frame image. So basically the design is very complex and odd, I've heard that there is a way to make this fit automatically on every screen on IOS, they called it auto layout i guess. Is there a counter part of this on android? Thank you.
Try using a GridLayout. You should be able to achieve what you're trying to do. There's a good blog post here.
I'm building an e-Book reader for android. The content of an ebook is often divided into html files (epub) with one or may chapters in them.
I'm planning to build an e-book reader who divides the content of those files into different "pages". The problem is to know how many much text "fits" on one page and to calculate the correct amount of pages since that depends on a number of different factors, such as: font-size, word size, paragraphs, images, page-breaks, headlines etc.
Idealy i would have my text justified and selectable, and since that's not possible with normal TextView or EditText i must use a non-scrollable WebView.
So to sum it up, how can i "measure" how much text that fits on one "page" on my WebView? Or is there a different better approach to solve this? I saw that the Paint class as support for measure text and breakText.
Thanks!
Note : This answer does not use the webview as your display surface.
You can use the Canvas to draw each page. The canvas gives you it's height & width using which you can draw each line on the canvas using drawText based on the width & height available.
Basically you can calculate how many letters can fit in a line , take that many words , taking care you don't split any words and keep drawing the text.
If you break up the tasks to use different workers for each paragraph you can also probably make it fast.
Maybe you can do it like this
Text is being added and rendered inside WebView
In WebView, you can use Javascript to inspect the current state of DOM tree and extract measurements like width and height of individual elements
Javascript communicates back the size of the page back to WebView creator thru some callback
When Javascript detects that the page size threshold is exceeded it sends a signal for a page break needed
Android HTML5 Kindle does page breaking with Javascript so it is definitely possible.
Take a look at the source of FitText or perhaps here. Both figure how much text can fit in a given space. You may be able to borrow ideas from them and adapt for your purposes.
I am an experienced developer, but I'm inexperienced on the Android platform. So I am seeking some advice from developers with more experience with Android.
I am building a Honeycomb application using Fragments. One of the fragments calls for a vertically scroll-able read-only "HTML table-like" view with dynamically loaded data. Similar to a spreadsheet, I should have clickable headers which I can implement server-side requests to filter/sort the data.
I am pretty sure this Control doesn't exist yet, am I right? Do I have to build it?
Assuming I have to build it, which existing widget should I extend? ListView, Table, GridView?
I assume I would have one widget for the header, and then wrap the body of the table in a scrollable layout to handle scrolling while keeping the header visible. I am concerned that I might not be able to guarantee that the headers line up with the columns.
Thanks in advance,
Tim
Android layouts are pretty basic - there are not any shipped layouts that will really do what you are looking for automatically, but you could probably do what you want with a heavily controlled gridView. Android is also pretty bad about controlling multiple elements to fit within the screen size, as it's goal is to support multiple screen sizes and densities.
From what I understand your desire to be, I think the best solution is to create a nx2 grid view dynamically, and control the width of the view based on the device size. You would have n number of headers on the top, and you could fill the lower half of the grid with your textViews, or whatever data you wanted. The hard part would be keeping the widths of the grid elements under control and on the screen. In addition, you will probably find that you can only fit a small number of header items on the screen because of the phone's small size, so you may discover a better layout to fit your needs.