How to show and hide layout dynamically - android

I want to make layout that expands dynamically, like some kind of menu.
It should look like this
http://imageshack.us/photo/my-images/845/dialog.jpg/
Step 1:
When I click on TextView it should inflate the new layout, remove transparent one, and move text to the left side.
Step 2:
When I click again on TextView (it's vertical custom TextView btw) it should go back to Step1
I want to put this layout into custom dialog and it should always be on my right side of the screen?
Any ideas how to solve this?
I can do this with two layouts and changing contentView of dialog on every click, but it seems like a very dirty solution. Is there some nice and fancy way to do this?

The simplest solution is probably just inflating all the Views, set their visibility accordingly, and move the TextView when the user clicks on it.
From the looks of it, it seems like you want to slide between a lot of views by clicking the TextView? If so, you might want to look into something called ViewPager, with a little customization you might be able to archive that.

Create two different layout's mentioned in images like 1) layoutone.xml 2)layouttwo.xml
Now crete on linearlayout in add that layout in your alertdialog. Also add layoutone in that linearlayout by inflating that layout. Now on click of that textview just removeallviews from that linearlayuout & inflate second layout & vice varsa.

Related

Create a Dropdown to show more Views in Android

I am trying to code a layout, but I do not know well how to approach it.
Initially I have the following:
When the user click in this View, I need to show:
I thought I will need a Spinner, but the content that is shown when the user click is not a list but a set of Views (In this case, it will be a LinearLayout with a Spinner and a EditText).
I am a little lost, what would be the best approach to achieve this?
Do I need to implement a CustomView?
Sorry if it is a dummy question, but I can figure out how to code this Layout.
I think the best approach would be to make a LinearLayout in wich you can place you Spinner and your Search EditText and set this LinearLayout ViewGroup setVisible(View.INVISIBLE).
Then when you click on the "registra alimento" View set the LinearLayout below to setVisible(View.VISIBLE)
To fade it in:
Animation in = AnimationUtils.loadAnimation(this, android.R.anim.fade_in);
viewToAnimate.startAnimation(in);
viewToAnimate.setVisibility(View.VISIBLE);
Take one Linear layout add Textview of Registrar alimento than set linear onClickListener with visibility of Spinner and edittext.(Also maintain flag for visible invisible )

2 LinearLayouts in the same position

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. :)

right approach of custom view implementing

I need to implement such a element - TextView of predefined size with white border line at the bottom. Inside of the TextView a button with predefined style and size should be. TextView shouldn'y be clickable and button should be. I see some possible solutions:
1) implement TableLayout and put all my buttons into the table's row. But there's not nice solution - my layout becomes too long. So I think about another solution.
2) make my element as a custom view. But the problem is that I need to use a lot of these elements through my app and I need use onClickListener to each of them. I know how to implement onClick() method for all items but how I can use singular onClick() method for each of the item? And how should I build this custom view - should it be extending from RelativeLayout, where TextView and Button with defined properties should be put?
I also thought about using for the button, but in this case my TextView will be also clickable.
Tell me please what approach is less complicated and more convenient.
I used another way if solving this issue. I put buttons and other control elements into the TableLayout with predefined TableRow style. In this case I do not need implement TextView and borders margins which I need I build with corresponding TableRow style.

Android: How to change layout in code

I have basic knowledge of layouts and so far in my applications I always had one static layout for each Activity. Now Im trying to create a single Activity with a basic framework (Title, some buttons) and a Layout I need to change after clicking a specified button.
Example:
I have a Title bar, a Linear Layout under it and 3 buttons under it. After clicking one of the 3 buttons I change the title text and the button appearance. But I also need to change my Linear Layout between Title bar and buttons. I didnt know how to do this exactly, so I made it Linear Layout in my main.xml, but after clicking one button, I actualy need it to be a Table Layout (or a List View), after clicking another button I need it to be a Relative layout. I hope you get the picture. In all cases I need to add some elements into it (table rows, some views etc.)
My question is, what is the best way to acomplish this? Thanks!

Android: How can I create a layout within a layout ?

In my app I want to have a button that if the user clicks it
than a new layout is opened within the current (acually the main) layout.
the new layout should not fill all of the screen and parts of the previous layout
should be grayed out.
Any ideas on how to do this ?
You can show a hidden layout within your button's onClick event by calling
view.setVisibility(View.VISIBLE)
You can also fade out view elements or whole views with
view.setAlpha(75);
view.setBackgroundColor(Color.GRAY);
Note that "view" in the first example is your layout element.. LinearLayout, RelativeLayout, etc. and in the 2nd example, "view" is the element(s) you're trying to gray out.
Follow the answer of SBerg413. And for more information. you can take the relativelayout for the part that you want to hide and display on the button click.
And as like SBerg413 answer. you can hide the respective layout and show the layout you want to display.
Hope it will help you.
Thanks.
you can use a ViewFlipper to achieve what you want, position the viewflipper where the child views should fit (part of the screen you say)..
Inflate the rest of the "child" layouts from other xml, add them to the flipper and switch between them when you want...

Categories

Resources