I have a layout.. The 70% of it occupies a view then i have a button on the 30% left.. on click of the button, i have an activity that should be displayed only on that 30%. what happened is, it displays in full screen since i used startActivity(myIntent)... can anyone help me how to start an activity by getting only a certain portion of the layout and not as a full screen? Thanks you!
You may want to look at the Fragments API.
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.
Check this post to use it on android < 3.0: http://mobile.tutsplus.com/tutorials/android/android-compatibility-working-with-fragments/
Activities starts in fullscreen always. You may create layout where 70% of screen will be transparent and 30% of screen will be filled by views.
The question you are asking is may be to hide the required view while starting the activity .
so for that just set the visibility of that view as invisible.
so to just hide.
reqview.setVisibilty(View.INVISIBLE)
in this case your view will be invisible . but it still takes up space for layout purposes.
reqview.setVisibilty(View.GONE)
in this case your view will be invisible . and it doesn't take any space for layout purposes.
may be this help you.
you can give the next activity as transparent activity so that it will be displayed in 30 % of the previous activity.But the problem is that you will not get any event for the remaining 70% actvity. if you want like this then go with the transparent activity.
If you want this then look into How do I create a transparent Activity on Android?
TODO
btn1.setVisibility(View.INVISIBLE);
Controls the initial visibility of the view.
Must be one of the following constant values.
Constant Value Description
visible 0 Visible on screen; the default value.
invisible 1 Not displayed, but taken into account during layout (space is left for it).
gone 2 Completely hidden, as if the view had not been added.
This corresponds to the global attribute resource symbol visibility.
Related Methods
setVisibility(int)
Related
I want to make an animation on click that a button slides down to the position of another button and at the same time I'm loading another activity. This other button is on the new activity. Picture it as if a button from one activity is replacing a button on another activity, so it has to slide down to where the new button is.
Can I measure this new button's position before the activity is loaded? So I can get the animation right for all screen sizes.
Activities are designed to be used as full-screen components, meaning that you understand that the other activity that pops in is going to take the full screen. If that is your goal, you can use shared element transitions with the activities to get the desired effect: https://developer.android.com/training/transitions/start-activity#start-transition
On the other hand, if you need both activities to stay on the screen, than you should rather to use fragments, as activities are not suited for that. For more info on that approach, see here: https://developer.android.com/guide/navigation/navigation-animate-transitions
I've got a problem that I'm having problems solving. My app has 2 types of fragments. When the app starts, a fragment with main menu is added to a FrameLayout that I use as a fragment container. This fragment takes up the entire screen. Then, when I choose one of the items in the menu, a corresponding fragment should be loaded into the container, replacing the menu. However, this fragment must only take 1/4 of the screen from the left, and the space outside is to be used by some other fragment.
I was thinking about making 3 FrameLayouts, one for the left side, one for the right and one for the entire screen, but this is going to have problems with fragment transactions, since I would have to keep tabs on which fragments are where and remove them by hand.
Basically what I need is some way to change whether my fragments are loaded into a container that takes up full screen, or a container that takes up only some part of the screen. I probably could do it with tons of trail and error and some code, but I bet there is a really easy way to do this in android that I missed.
Instead of trying to dynamically load these fragments into the various containers, I would suggest having two different Activities.
It sounds like the main menu fragment will only ever appear on its own in full screen. So, make that a full Activity (let's call it MainMenuActivity).
The second activity will have two FrameLayouts as it's contents, with one taking up 1/4 of the screen and the other taking up the remaining 3/4. Load this second activity upon choosing a main menu option and populate the fragments in onCreate() of the second activity.
Hitting the back button from the second activity will return the user to MainMenuActivity.
I want to make it possible to display a fragment on top of every activity (if the right action is called). It should look like a window on top of everything. This works fine so far, but I am a bit confused about how to get the layout integration working.
When I wanted to display something like a fragment on top of everything, I had to use a RelativeLayout as the root element, then nesting maybe LinearLayout (containing the activity's layout) and fragment.
Is that the only way to achieve this? Do I have to refactor now every activity layout to use RelativeLayout as the base? Or is there a more straightforward way?
I cannot comment, so will write here. Please provide some code to express what you mean, much easier to understand it than. If i understood you correct, u want to have a window on top of another window?
Cannot see why this would be voted down, and not even a comment for the reason :/.
You might achieve what you want with an overlapping fragment. I have had this side effect when making my app, i.e. that a fragment view is transparent on top of another fragment. To achieve this, just skip if(savedInstanceState != null){return;} in your onCreate() in your activity. And instead of replacing a fragment (transaction.replace) use (transaction.add)
Is there a way in an Android Activity to do a setContentView(), so that I can have Android compute the layout, and so I can successfully get Views in it via findViewByID(), but not yet display it?
This would be in an app with a main activity and some subordinate activities and the one I want to start but not display would be one of the subordinate activities. (in other words the main view would already be filling up the screen, so it would be sufficient to simply keep the new one hidden at the bottom of the view hierarchy). The activity would be started with a "standard" launch mode.
If there's a way to do it by keeping it at the bottom of the View hierarchy, how would I force it to the top when I do want to display it?
NOTE: This app already exists - it's a large, complex industrial app with 14 Activities, written for Android 2.35 and 2.36, so re-architecting it to use Fragments instead of Activities would be impractical. I just want to modify one Activity to not display, or to just display at the bottom of the View hierarchy so it's not visible.
This would be in an app with a main activity and some subordinate activities and the one I want to start but not display would be one of the subordinate activities
That is not possible. Or, more accurately, you are welcome to start that activity and not populate its UI, but it will still take over the screen, and so the user will be presented with a blank screen, which is not especially useful.
in other words the main view would already be filling up the screen, so it would be sufficient to simply keep the new one hidden at the bottom of the view hierarchy
Each activity has its own view hierarchy. A "subordinate activity" cannot and will not be at the top, bottom, or anywhere else with respect to some other activity's view hierarchy.
Im quite new to Android but I think that this can bea easily done using fragments. One fragment will be the one that will be currently shown and the other will be overrlayed with a hiden parent view for an example. When you need to show the other fragment just set the layout to visible.
Hope it works, Good luck.
If you want to do this without using Fragments which I suggest you to use them you can use LayoutInflater to inflate whatever layout you like and change between them using setContentView repeatedly.
View layout1 = LayoutInflater.from(this).inflate(/*your first layout */ R.layout.activity_layout_1, getWindow().getDecorView());
//here you can use findViewByID like this
View someViewInLayout1 = layout1.findViewByID(R.id.some_view);
//... get fields for all others views you need here in layout1
//than you inflate your other layout
View layout2 = LayoutInflater.from(this).inflate(/*your second layout */ R.layout.activity_layout_2, getWindow().getDecorView());
//... do the same for layout2
Now you can call setContentView whenever you want to change between layouts.
setContentView(layout1 /*or layout2*/);
I want to implement one android activity that have a button inside of it. when this button is clicked , andother activity runs.
The second activity slides from left to right and get just 80% width of the screen , and the 20% remaining spaced should be filled by left side of first activity( first acitivity slides to right)
How can I implement it?
I think I should have two activity in one screen!
I think Android Does not support two activitis in single screen. insted of activities u can use fragments
Better you should use fragments .. Check here http://developer.android.com/training/basics/fragments/index.html