Right way to implement this layout? - android

Here's what I want to do in an app, hope it's clear:
NOTE: I don't want to have all 3 views on the screen at once!
I have a search window, I have results, and I want to show details about a result item when it's clicked.
On a small screen (phone) it's pretty clear: I show one view at a time.
On a tablet, especially in landscape mode I'd like to show 2 views at a time, means:
[search | results] and when a result item is clicked, show [results | item detail].
My ideas:
Have an Activity "SearchAndResults", when result item is clicked, open another Activity calles ResultsAndDetails. Both Activities would use Fragments, eg SearchFragment, ResultFragment, DetailFragment.
This might be quite easy to implement but doesn't seem very elegant to me, especially because I can't have any animation (let the result view slide to the left, let the detail view slide in from the right)
Have all 3 view in one activity and hide/ show them with layout.setvisibility(). No animations either, and I hate to do too much layout stuff in my code.
A viewpager that shows 2 views, but can't be swiped by the user, only from code?
What's a good way to do this?

I would use Fragments, as in your idea #1. This question seems to be describing the exact same type of layout that you are trying to implement. It has several answers on how to animate fragment transitions, including complete code examples.

Related

Scrolling a ViewPager programmatically, by a small amount

I have the requirement for what is effectively two activities side by side, allowing the user to scroll from one to the other, and back. I've decided that ViewPager is probably the best way to handle this, but am open to suggestions.
When the activity loads, the left hand view is displayed. I want to indicate to the user that the other view exists, by just scrolling it a small amount to the left and back again (similar to the way it's now common to show that a sliding drawer menu exists).
I've tried a number of things but have yet failed to find a method where both the views scroll smoothly together. Another way of interpretting the requirement is saying I want to programmatically fake a user flicking the page briefly.
Try calling the method fakeDragBy(float)! According to the documentation you need to first call beginFakeDrag() to initiate it and then call endFakeDrag(). This will mantain the ViewPagers default snapping behavior, so once you've revealed the other screen is there you don't have to animate the transition back, simply call endFakeDrag and the ViewPager will correctly snap back to the last screen (As long as you haven't dragged it past the half-way mark).

Android: Activity sliding over another one with swipe gesture

I have two activities one with some data and the second one, semitrasparent with some buttons on it.
I want the second activity slide over the first one after the swipe gesture.
I've already read about ViewPager and it's not what I am looking for. I want the first activity still being visible over the semitrasparent second one.
I am looking for any suggestions how to do this.
Literally not possible.
The entire point of an Activity is that it fills the ENTIRE screen, and there are never 2 of them shown at the same time, ever.
So you can't swipe to "semi" open one with a slide animation.
To do that, you'll have to use 1 Activity, and multiple Fragments.

Navigate horizontally and hit a button to go another layout vertically

I've been trying to figure out how to go about doing this specific task, but I can't quite figure out.
So, I have a ViewPager setup with 2 layouts that work perfectly. In the landing Pager, I have a button. What I'd like to do is, hit that button and the page animate vertically (up) to another layout.
I got the similar movement with starting a new Activity, but the problem with that, is that the title bar gets animated as well. So it doesn't give this fluid motion to the layout above.
I tried several things, but came up short with a lot of crashes.
Then I was thinking of having the landing Pager be a ScrollView and stack both layouts on top of each other, and navigate to a specific id, but came to no avail.
Does what I'm saying making sense? How should I go about creating something like this?
So to summarize.
Land on a page where you can swipe to one additional page (left).
Be able to hit a Button (on landing page) and animate up (vertically) to another layout.
All of this while having a static title bar.
Thanks in advance.

display large string into multiple pages in single activity

I am very new to android development. I am trying to create a simple two activities based ebbok type application where activity1 is table of content and activity2 displays the details. I have a listview in Activity1 where I list the table of content. On clicking any specific content, I load activity2. In onCreate of activity2, I load the content into a string(from a txt file in assets). and display that in textView (as defined in activity2.xml). So far so good. The challenge now is to display the content page-wise because, as of now all of my string gets loaded into a single page in activity2. So I added two buttons at the bottom of activity2 (defined that in activity2.xml). My planned logic now is
get the screen height (I could get that)
get the botton height and substract 2) from 1). Now I cannot do this becuase I cannot get button height in onCreate of Activity2
and then find how much text I can fit in one page, find number of pages accordingly, use a page index and using a page delimiter, keep loading remaining text into next pages when user clicks "next" button.
So i need help with
-how to get button width as I have mentioned in 2)
-and any sample code you can share to perform 3) above will also help me.
any help here from any one of you experts out there will be much appreciated.
Using Fragements will Solve your problem.
Fragements :
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 fragment in multiple activities. You can think of a fragment as a modular section of an activity, which has its own lifecycle, receives its own input events, and which you can add or remove while the activity is running (sort of like a "sub activity" that you can reuse in different activities).
For example, a news application can use one fragment to show a list of articles on the left and another fragment to display an article on the right—both fragments appear in one activity, side by side, and each fragment has its own set of lifecycle callback methods and handle their own user input events. Thus, instead of using one activity to select an article and another activity to read the article, the user can select an article and read it all within the same activity
For More About fragements just go through this link.
Hope it will help you.
I figured out a much efficient way to display a long string across number of pages. -I display the long text into the text view and disable scrolling -I then find out the lines in the layout and lines on single screen, hence I know how many screens(pages) will the long string span across -Then whenever user clicks a button to go to next page or swipes screen to go to the next page then I use TexView.scrollTo() function to move to number of lines(as many on a screen) forward. So it becomes as good as moving to next page

Android - How to change Activities within a TabActivity?

I currently have a TabActivity which has 4 tabs, within one of the tab's I want to be able to move forward and back between 4 different Activities.
However if I try to start a new Activity now it removes the TabActivty and starts a whole new Activity with no tab bars.
I have read about using view groups but that this is not best practice and also about using a view flipper but this doesn't seem to let me switch between different Activities only change the views within the Activity. I can't implement back functionality for exa,ple.
Can anyone point me in the right direction as to what I should be looking for as a solution to this?
EDIT:
Some more information:
Within the TabActivity my first screen will be a ListView that contains 4 rows, then selecting one of these will in turn load another ListView with 2 rows again within the TabActivity and then the 3rd screen will just contain some text depending on which option the user chose again within the Tab Activity.
Is a ViewFlipper the best solution here? It seems to me that it will require a lot of coding within one Activity if I use the ViewFlipper?
I have done something similar. I used the ViewFlipper to achieve this. You can override onBackPressed in your Activity so you can deal with moving back through your views.
There's a couple of ways of doing this but a simple way would be to just increment a counter in your Activity as you move to the next views, then in your onBackPressed method if counter != 0 just show the previous view, if counter == 0 call super.onBackPressed.
You can see in my video showing what the result could look like (ignore the bug being shown in the video).

Categories

Resources