So what I am trying to do is to have 2 invisible LinearLayouts with buttons they will be from the start to the screen.
On the onClick event one of them will appear with a translate animation,when the other is invisible and then on the other onClick event to close the open one and open the new one.
It will look similar to a sliding menu with the animation.
I want to know how the xml will look like in order to do that.
If it's possible with other layout (RelativeLayout), I also want to know.
Any tips on that?
There are multiple ways to achieve it.
Relative Layout definitely being the one as you your self know. :)
Add both the LinearLayouts with layout_width="match_parent" and layout_height="match_parent" and then toggle between them using setVisibility(View.GONE) and setVisibility(View.VISIBLE). Since View.GONE will remove one Linear Layout the other one will occupy the entire screen in its absence and vice versa.
You can also use FrameLayout. This by default places its children on top of each other.
Suit yourself. :)
Related
I have two layouts, manageLayout and mainLayout. They have constraints to the parent on all sides. I need in a one time have manageLayout on the top of mainLayout, and on the other time mainLayout on the top of manageLayout. Of course, there is sense in using visibility=gone on one of them, but i need one layout on the background of another. Problem: layout on the background handle events from top layout. How to make lower layout(and his elements) untouchable when another layout is risen?
Layout tree image:
LayoutTreeImg
Code sample, where i want to disable communications with lower layout: https://pastebin.com/PeL7u3YD (not only isSaveEnabled=false had no effect, also isEnabled=false had no effects too)
If you just need an explanation.
Once you've initialized both your views for mainLayout and manageLayout, you will need to set an empty onClickListener on both of them. Basically, layouts should get the click but do nothing. This way you can block the layout and widgets underneath the view on Front from getting clicked.
Now for for switching view to front maintain a boolean to know which view is on the front and on your button click set the other view bringToFront() (Or try some other ways mentioned here if you want) and don't forget to switch the boolean value.
Let me know if this works for you or you have any issues regarding this.
According to my perception, you can make lower layout setEnable(false). I hope it will work.
OK first I'm not actually moving buttons I'm moving imageviews that have an onclick listener. What I want to do is drag multiple imageviews around inside a layout. I was going to use a FrameLayout but it seems that wont work for multiple items.
Can anyone tell me which layout is suitable for this?
thanks in advance
Linearlayout with a vertical orientation should do it for you..use margain_direction for fine tuning it further
Maybe a GridLayout would suit your needs? You can have one or multiple child views in each grid cell.
I want to have a page in an app have multiple buttons (in grid fashion) I was wondering if it would be better to populate a grid layout with buttons or manually add buttons to a relative layout, or if it even matters. I want each button to do something different so if using a grid layout is better how would I do this. I know you need to have gridview.setOnItemClickListener but that would make each button do the same thing (I think). Any suggestions would be appreciated!
If you have a fixed number of buttons, use a RelayiveLayout or TableLayout. If you have an unknown number of buttons and want to be able to scroll through them, that's the time to use a GridView.
We have layout which contains imageView, textView1, textView2.
The goal is to make available sliding like in photogallery. But where to set OnTouchListener?
On layout? It is covered b other views. On every view? it seems also not a good solution.
I was told that I have to add one more layout that will fill_parent (on the level, where textViews and imageView). It will be invisible. I did it, but it also does not work good.
Thanks.
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.