I want to dynamically hide/show controls in an activity based on a button touch event: when the user presses the "details" button, I want to show more controls in the same activity.
What is the best way to handle this? Is there a way to do TextView.Hide()? Can it animate the transition?
setVisibility() will allow you to make a widget visible, invisible, or gone. The difference between the latter two is that an invisible widget still takes up space, while a widget that is gone does not.
Android has an entire animation framework for slides, fades, spins, and the like. Here are two sample projects showing some of this.
Related
Hello I want to add a LAyout to my Activity.
I have a FrameLayout where I add a SurfaceView so far.
Now I want to add another Layout as a menu over it so when I click a Button on my Surface View I set it to be Visible.
This layout should contain one Textview and should be scrollable
1: What is the best LAyoutout thing for this approach? I thought of a Listview where I add Strings dynamically
2: How can I achieve this in Code?
It should be:
Scrollable.
Should be a certain Size: Half of the screen width and half of the screenHeight
So it also should be at the position screenWidth/4 and screenHeight/4
To achieve this I can set these parameters inside my mainThread that is attached to the surfaceview so I have the parameters needed allready in Pixel format that's no Problem.
It should loose the Focus when the User taps outside of the view so my surfaceView gets the Focusagain and set the LAyout to Gone.
So it should go like this:
User taps the button to display the menu
Now the User can scroll through the Menu
When he presses the Backbutton or outside of the View It should close itself
When there is a new Text that should be displayed it should be attached to the layout to be ready to be displayed at the next time the user clicks the button again
Thank you
1: What is the best LAyoutout thing for this approach? I thought of a Listview where I add Textviews dynamically
That sounds good to me, you can go with either ListView or RecyclerView. You are basically not adding TextViews dynamically, you create an adapter that will do handle creating and recycling of views for you.
2: How can I achieve this in Code?
Create a DialogFragment, it's the best candidate for such dialogs with logic. Its lifecycle is handled via FragmentManager, so you won't have issues on screen rotations and so on. It allows you setting whatever layout you need just like any other Fragment. It will be placed in the center for you, so you don't have to handle that manually. Just set the size of the dialog you want and it will look perfect.
It should loose the Focus when the User taps outside of the view so my surfaceView gets the Focusagain and set the LAyout to Gone.
I don't really get this one. When user touches outside, do you need to lose the focus but the dialog should not be closed? If yes, then this is already answered here:
Allow outside touch for DialogFragment
If the dialog should be closed, you don't have to implement anything, it works like that by default.
The questions are quite FAQ-type, but I can't find any suitable tutorial and don't even know what exactly to search for
1) I've got a list filled with linearLayouts and need to set an animation for elements added to those layouts as shown on image. The animation is the element slides from under the existing layout elements. If an element is removed, the animation is the same reversed
2) There is a screen filled with elements. Tapping, for example, a certain button, you call a pop-up, which comes from the edge of the screen and is above the rest of the elements.
If you tap anywhere, except the pop-up,
a) it will slide back
b) you will interact with the objects which the pop-up does not cover
What makes such effects possible? How to implement them and what to read about?
For 1) Setting animateLayoutChanges=true for LinearLayout should do the job
For 2) You can open a Dialog on button click and customise the animations for the dialog by calling dialog.getWindow().setWindowAnimations('id of animation xml')
Here's scenario:
I have a RalativeLayout holding ImageView and few TextViews.
There are "linkified" elements inside these TextViews such as URLs, phone numbers, etc.
Clicking on the links result in various actions, also clicking on ImageView triggers some action too.
Now - I want to have outer onClick attached to the complete area of RelativeLayout in such way that if user clicks on any spot withing the layout (but outside of the image and links) then it executes another action
Right now I have layout#onClick, image#onClick, and embedded links are processed by Linkify. Image and links clicks are working reliably but clicks on layout are captured about 50% of the time and I suppose would frustrate users to the point of tears. Any tricks that you guys can suggest to improve reliability? And if not what would be a good way of achieving this from the best usability standpoint?
Since no one came out with answer at least I can share my thoughts about the solution. Basically I decided not to fight overlapping click handlers and instead, start with onClick enabled on the parent. Then, when the parent detects the click it turns it's own focus off and lets other controls take care of clicks. I also added "Off" button that is visible only when parent is expanded and clicking on that collapses the parent and puts the focus back into the parent view.
Let me know if you know better solution
I have a ListView and each item contains a TextView displaying a number. I'd like to give my users the ability to change this number while staying on the ListView (as opposed to drilling down into a detailed view by clicking on the list item).
What I'm looking to do is to slide in a layout from the bottom of the screen that covers about half of the screen. I'd like this layout to be OVER the Activity behind it (as opposed to being part of that Activity's layout and simply showing it). I'd also like it to be model (or seem modal). Meaning the Activity behind it can not be focused and manipulated. In this layout I will essentially create a calculator.
What I need help with right now is:
1) How to display a layout over the current Activity
2) How make the background (the Activity) modal
Could someone point me to some tutorials/resources and/or give me a few tips?
use an Animation. here is a small tutorial on them: http://developerlife.com/tutorials/?p=343
initially, the view you want to be modal must be placed where you want it to show up(and visibility set to gone).
use a translate animation to visually move the view from below the screen to halfway up the screen. once the animation starts, set visibility to visible
try disabling all views that the user should not be able to interact with after you have started the animation holding the calculator view
I'm using a FrameLayout and have two buttons on it, button A and button B (in addition to some other widgets). A is directly on top of B, overlapping completely.
In onCreate, I do a check and if A is not needed, I set it to invisible. Later in the app it may become visible again so I don't want to remove it completely.
When button B is pressed, it doesn't respond. I think button A is stopping the press even though it's invisible. Other buttons do respond so this is why I think this.
Is there a common way to make it so B accepts touches? Do I have to remove A? I don't really want to remove A as I have a relative layout in the frame layout and other controls depend on A for positioning.
Personally I think it would make a lot more sense to have a single button who's properties vary based on configuration. However, if you really want to have two, you could try a couple of things:
Set the invisible button to not be focusable or touchable.
Set the button to Gone, not invisible. This might mess up the layout though, since this basically says not to consider the button when doing the layout.