I would like to know how to go about doing this small problem that I am encountering while making a video player app.
On clicking the first control(the rectangular icon) in the above image the following view must be displayed instead of it which I am quite unsure as to how to do it. Here is what it is replaced by
Also please note, by any chance the activity should not be changed. I have been able to design the views individually but having problem changing them at runtime when user clicks. Could someone go about explaining as to how it can be done or provide some suitable links to achieve my goal. Thanks.
For something as simple as this you can just change the visibility of the views.
view.setVisibility(View.INVISIBLE)
Or the more effective:
view.setVisibility(View.GONE)
Do that on the views you want gone, I suggest a wrapper class. It's either this or changing the contentView as describded below.
this.setContentView(R.layout.newLayoutToUse);
However, I have a feeling there is a better way to do what you want. It's overkill to load a complete new layout if you just want to change the image of some buttons or imageviews.
This might be a stupid solution, 'cause i'm terribly tired right now, but why not use the bringToFront() method on the View that you want to display in the front? Display them both in front of each other, maybe in a RelativeLayout, and then swap between them as you wish.
They are small objects, so don't consume memory. I don't see why this shouldn't work.
OR
Place them above one another, so they overlap and then make the above view visible/invisible depending on which one you need to display.
OR
just remembered I read somewhere that you can scroll through a ScrollView automatically from code. So display both Views in a ScrollView in succession and when pressing the button or whatever, you scroll down to make the next menu visible. When pres back, you scroll up to make the previous thing available. Should work, and might also make a nice animation between changing of the menus.
Related
I have an EditText in my layout which is used to get the search query from the user. I want to show a LinearLayout bellow it when user enters some characters and fill it with the results (This layout should appear after entering at least N characters). But I don't know how to show this layout?
I thought of putting the whole layout shown in the activity inside a FrameLayout and add the view when required, but there will be two problems:
The view will be added on the top left of the screen.
If I want to move it with adding some padding to it, all the area will correspond to the click event.
To explain what I want more, please take a look at this:
I hope this link will help you, you need to use AutoCompleteTextVIew
http://www.javatpoint.com/android-autocompletetextview-example
https://www.codeofaninja.com/2013/12/android-autocompletetextview-custom-arrayadapter-sqlite.html
These is two approaches for your case.
Use AutoCompleteTextView
Use android-popupwindow.
The former is easier and more acceptable, however if your want to customize the layout of the resulting search, for example arranging them in a gird view, you may what to use the latter option.
Although, AutoCompleteTextView internally uses the latter option.
i'm having the next problem.
I have two layouts, one behind the other. When I click on the first view the "click" pass trough the view and it arrives at the second one. How can i stop the onclick only for the first view and enable it when i want at the second view?
Thanks in advance.
EDIT
A image with my problem
2EDIT
Why am i doing this? Because i put im my app a menu like facebook. So i have the menu in the red view and i animate the green to the right to see the complete menu. See http://venturebeat.com/2011/12/07/facebook-for-android-upgraded-with-better-navigation-faster-photo-views/. Seems that the solutions is with set the view clickable to false.
It's not clear what and how do you want to achieve, but it doesn't seem to be a good idea to have RelativeLayouts on top of each other. For this you could use a FrameLayout, or if your layout is a bit more complicated, you could play with setting the views unclickable.
If this doesn't help you, please post some code.
EDIT
It's still not too clear why do you want to achieve this, but you can set the second view unclickable, whenever you want.
I have an activity with more then 200 diffident views and layouts. Some of the views are images and some are texts or buttons. The visibility of the views changes from time to time, and so some of the textView contents, but nothing more.
The problem is with devices with big screens when the activity is out of focus and gets deleted from the stuck (see here under "Saving activity state" section). Unfortunately, to restore it with onRestoreInstanceState() , is a real mess.
I was wondering maybe I should not use Views but implement it in a different way in order to save memory?
Maybe just bitmap images on a Canvas or something else?
Any suggestion tricks, tips will be appreciated.
I suggest you to use Fragments, if you have a lot of views and layouts in one activity.
you can use any number of views as layout, you saying that it will change depends on time,
use setVisibility(View.Visible)
setVisibility(View.GONE)
setVisibility(View.INVISIBLE)
just wondering if anyone else has a better suggestion that what I'm coming up with.
The issue is to do with a TabLayout, 5 Tabs all using a single Activity. Each Tab layout contains quite a few fields so the main parent on each tab is a ScrollView.
What I currently have is a 'Save' & 'Cancel' button sitting outside the scrollviews so theyre always visible and there for the user regardless which tab they're on. The problem is that since I'm using Tabs and always have these buttons visible when they are editing and the IME is displayed, they'res barely any of the form visible.
So I think the best thing for me to do is to probably show the buttons at the end of each scrollview. What I don't like about this is as I have 5 tabs, it will mean I have to declare 5 sets of the buttons, and of course define them and bind them in the Activity.. which seems rather messy and inefficient.
So if anyone has any better ideas I sure would love to hear them :-)
Thanks
Rgds,
Dave
Some of the options you got is
Try to put a title bar, and move the save and cancel buttons there (Small image buttons).
Save can be moved to the menu too (not recommended).
Auto Save functionality can also help, depends on how useful is it to you.
Try to use custom images for tabs, and make it take less space.
else, remove the save and cancel buttons, after the user makes any modifications, and presses back, prompt him to save the unsaved changes.
You could make it that when you're in tab X, the tab button for tab X now becomes X(save), so if they click again on the tab button in the same tab, it saves. That saves you five buttons, potentially...
Define programmatically the buttons inside a LinearLayout and add them to each ScrollView with addView. The code of the buttons should check in what tab are we at that moment, and act accordingly.
Then you'll have the same two buttons arranged in the same way in all your ScrollViews.
Or, if you dislike doing it programmatically, do a layout for the buttons and use View.inflate of that layout, and add them via addView to the ScrollView.
The views are not cached in a ViewFlipper. Is there a way wherein we can get an image of the view and show it to user so that he sees the Ui as we see on Home scrren(when we swipe the previous view also moves along and when we lift our finger, only then the next view is shown completely.)
What I want to do is that when the user starts moving his finegr on screen, the view should also move along(create an image of view).
I am not getting to do this, as when we swipe the present view goes and next view comes, we do not get both visible when we r moving our finger on screen.
Please if anyone gets what I am trying to do, do help me.
Thanks,
Farha
It's tricky to get scroll and swipe tracking working on Android, while using ViewAnimator or its subclasses.
They allow you to set in and out animations and start them at a given moment, but they work with discrete, either-this-or-the-other-view animations. They are actually using FrameLayout and after in or out animation is executed, other views' visibility is set to View.GONE to hide them from showing up under/over your current View.
The Launcher and the Gallery application are actually doing the functionality you want, by using a different approach.
They track the user touch input (onTouchEvent()), on MotionEvent.ACTION_MOVE they perform animations manually and on MotionEvent.ACTION_UP snap to the appropriate view, just like in the iPhone.
Unfortunately, this approach is actually more complicated than it looks like.
With the manual handling, you have to ensure that you are taking care of everything related to the touch input. This includes a lot of flag-raising, value-checking, event-delegating, etc.
If you want to get better acquainted with this, take a look at these classes from Gallery3D or Launcher's source code.
One other way to get nice horizontal scrolling is to use HorizontalScrollView.
You have to figure out a way to recycle your views, like you would with a ListView and you have to add the snap-to-view logic, but if you have to take care of a small number of views it could be the easiest approach.
Hope that helps.