Is there a concept of partial layouts that can be changed during runtime without sliding? - android

I'm trying to find out what technique I have to use with my intended approach.
I have a layout that should consist of 3 parts: a top and right part that stay the same and a left part that can change in runtime. When the user decides to change this left part, it should display another layout at that location.
So far I've found these approaches:
ViewFlipper
Not really what I'm looking for since it's used by sliding your finger to the side instead of pressing a button
ViewPager
Seems to be pretty much the same as the ViewFlipper.
ViewStub
Can only be used once so not a viable option (I want the user to be able to change back and forth).
Sadly, none of them do the job (unless I have misinterpreted something). Is it even possible to do what I want?

If it's something not too complex, you could go with ViewAnimator.
For something more advanced Fragments are the solution.
Note: You could call setDisplayedChild() on a ViewFlipper to programmatically switch between views.
You could also call setCurrentItem() on a ViewPager (which by the way can use Fragments).

Related

What is the best way to build app architecture( activities and fragments)

I am building app right now. I am trying to follow all design patterns and google suggestions for building responsive apps.
Firstly, my app will contain navigation drawer.Of course my app will have several activities. So I have searched the best way to have navigation drawer on all activities, I found that the most correct way is to use some BaseActivity class which will have navigation drawer in its layout and framelaout for storing each activity representation(container for fragment). It can hold fragment, but the problem is that only one fragment.
So I have faced this problem. I am going to design following activity
So as in the picture I wanna to have image slider at the top , and some other layout parts under this slider for example grid layout, list or something other.
I think it would be better to separate image slider and other part, for example when my scree will be in landscape orientation it should be replaced but something other.
Futhermore others activites also gonna to have several independent parts for example list and anything other widget.
But as far as my activities should extend BaseActivity class, they would have only one place(container) for storing fragment.
I have tried to think about ways to solve this problem , and I have only one idea is to create several fram layouts in base activity(equal to max fragments used on child activities) and setting them visible and invisible depending on needs, but this approach pretended to be only way of hidding problem.
I don't know what is the most correct way to implement such type of application, so I need help or advices from more experienced developers to build my app correctly and bring user good experience.
I hope you can help me.
Thanks.
To start with, the container in your BaseActivity does not have to necessarily be a FrameLayout. For example it could easily be a LinearLayout with android:orientation="vertical", so that all fragments you add in it will stack one below the other.
Also each fragment can has other nested fragments in itself (although that's generally not the best practice, as usually it indicates some bad UX decisions).
Both those said, I think you just use the first point I made here. Now if you choose this one, I'd expect the question how to handle tablets and other big screens? Best way to handle them is to create a new landscape layout for your BaseActivity, where the fragments container might be different, for example a RelativeLayout, a LinearLayout with orientation="horizontal" and so on.
Good luck!

What is the best approach to design a set of "guiding screens" for an android app?

I need to design introduction walk-through screens when my app launches. It can be done by simple ViewPager or horizontal scroll view (?) but the additional requirements which are hindering me from using these are
A lot of animations on each screen
Animations will be bound to scroll position (i.e., current stage on an animation will be determined by how much user has scrolled, and it should roll back animation if user scrolls back without finish gesture)
Some items need to animate across different screens (e.g., There is a box on first screen, when user scrolls to the next screen, the box becomes larger without moving and a graph (a part of second screen) also comes into display under it)
I dont know if I explained the scenario well enough so please ask for clarification in comments. I need just a direction to control/approach/library.
Thanks
I'd recommend this library : ShowCase
In this way, you can make interactive tutorial and walkthrough your app.
You can also take this library and add some functionality.
Use viewpager, for each fragment you can use different animation inside that fragment, each fragment is independent from other views/fragments
You can use horizontal scroll view but it will take extra time and difficult to code
Seems like a ViewPager has everything you need.

Android: more than 80 views; Viewflipper or Fragments (or something else..)

I'm building an app where you can edit a detailspage. Right now I set the visibility to GONE and to VISIBLE because all the Views (for showing and for editing) are in the same xml file.
That makes more than 80 views, so I got a Lint message that this causes bad performance.
My Question is cann I use ViewFlipper (and is it possible to use two xmls for this) or do I better make use of two Fragments?
(fyi: I am also planning a animation between showing and editing, if that changes what I better do)
thx in Advance
You do not need either: a ViewFlipper or two fragments introduce unnecessary complications. I would separate showing and editing on different layouts (one XML file for each), and construct a different activity with each layout. When the user clicks on "edit" start the new activity (with an intent) and go to the edit screen. Then after saving the data just finish() the activity.
That is what we do, and it works great! Sometimes the "easy" solution is the best one, as in this case.
As to the animation part, there are already great answers here on Stack Overflow, such as here or here.
In case you want to keep the ActionBar while you animate between show and edit, two fragments would seem like the way to go. You can also have two layouts and inflate them independently, so that you don't accumulate so many views in one layout. Keep in mind however that (unless you create the ActionBar and fragments yourself) you will be limiting yourself to Honeycomb 3.0 and beyond.

Three listviews in one screen

I have an app on iPhone with cascading design like on the picture, and I'd like to port it to Android. Is there a simple and recommended way to do this?
The section menu on the left (Section A, B,C,D) is the first that the user needs to select, then the user needs to pick a category in the middle (all, popular, pc, xbox,...), then he is presented with a list of articles for chosen category.
I could imagine doing it with three ListViews, but then the app could also listen to a swipe gesture to make the rightmost ListView "full screen", and hide the first two listviews. I could implement a swipe listener for the whole activity and set first two listviews' visibility to hidden, right?
Are my assumptions correct and would this be the right way to do this?
It could definetly work the way you explain it - if the design is good is another discussion. Personally I'm not a fan of throwing in endless amounts of data in one screen, when the space is as limited as it is on most mobile phones (I would probably do it with 3 different screens with a ListView on each)
Implementing the mentioned swipe gesture is doable and you could certainly just hide the two other ListViews with the function setVisibility( View.GONE ).
Hope it helps.
You might want to use the new fragments API, it's specifically built for this kind of thing (and it's compatible all the way down to Android 1.6). Also, as KasperMoerch says, putting all that info on a small screen can get ugly. Using fragments will make it easier for you to gradually increase the amount of information displayed as the screen size increases.
I'm not sure you can just listen for a swipe gesture over an entire activity like that. I think you have to wrap the fragments in a custom view (for example an extended LinearLayout) and do the swipe listening there. However, achieving a finger-tracking animation (i.e. where the rightmost pane follows the finger precisely as it swipes across) is a pretty daunting task (I wouldn't really know where to begin, probably in the custom view though). The best way (I think) to do it is to make a compromise and just start an animation (right-to-left slide) when you detect a swipe. However, the simplest solution is to not animate at all.
You can also take into consideration dropping the swipe gesture altogether and just providing an "expand" button.

How to implement swipe pages [duplicate]

I'd like to make a view in my Android app that flips between multiple views on a swipe/fling. I'd like it to behave more or less like the Android Launcher behaves when flipping between views. In particular,
It should flip views on swipe.
Generally a swipe will flip between one view and the next. It should not fling across all of the views.
If you swipe slowly, you should see the views dragging as you're swiping, eg. the way the Launcher does it.
I tried using a ViewFlipper with a GestureOverlayView as per Romain Guy's blog post here, but there's no indicator to the user as they're swiping. This makes discoverability difficult, which is presumably why Launcher does it the way they do.
I tried using a Gallery object, but when I swipe from left to right, there's a certain amount of momentum that flings the users through all the views rather than just taking them to the next view.
Is there a good way to accomplish what I'm trying to do?
I know this is an old question but ViewPager is created for this exact same purpose. ViewPager is part of android compatibility package and more can be found at http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html
Take a look at HorizontalPager. It's actually based on RealViewSwitcher, which in turn is based on the Android homescreen's code, and supports snap-to paging with drag feedback, as well as nested vertically-scrolling subviews. Gesture support for fast swipes isn't all it should be, but this may get you part of the way there (and I'd welcome contributions back).
EDIT: As of 2012 you're much better off using Google's ViewPager - it's in the compat library.
Check out SwipeView within this project https://github.com/fry15/uk.co.jasonfry.android.tools It does exactly what you want it to do and is super simple to implement.
#CommonsGuy extended ViewFlipper to do it.
https://github.com/commonsguy/cwac-viewswiper
Ihaven't used this one yet so im not sure if it moves with your finger like the launcher if not your going to have to make an OnTochListener to do it for you in me.ACTION_MOVE you will update the view to change its position. I'll post some sample code when I get home if you don't get another answer.

Categories

Resources