How to make relative layout GONE inside ViewFlipper on condition - android

I have an XML, in that XML i have a RelativeLayout say R1, now inside R1 i have one ViewFlipper and inside ViewFlipper i have 7 relative layouts, Everything works fine if i load all seven on my UI, but on condition i want only 3 relative layout (inside ViewFlipper) to be shown on the UI. Can anyone help me to make rest 4 relative layouts to be View.GONE.
I tried setting them
if(X==Y){
findViewById(R.id.relativeA).setVisibility(View.GONE);
findViewById(R.id.relativeB).setVisibility(View.GONE);
findViewById(R.id.relativeC).setVisibility(View.GONE);
findViewById(R.id.relativeD).setVisibility(View.GONE);
}
but this is not working. I set this in onCreate under the require condition, but this view gets GONE only when the activity is launched and when i Fling here and there with the finger, all layouts come on the UI.
Now the only solution I am left is to create another XML with required relativelayouts, but the problem is my XML is quite heavy and i dont wanna use this last option. Kindly help

You could either use viewFlipper.removeViewAt(index) providing the index (position) of the View that you want to remove.
OR
You can use viewFlipper.removeView(viewFlipper.findViewById(ID_OF_RELATIVE_LAYOUT_TO_REMOVE))
There is also a helper method called
removeViews(int start, int count) which removes several Views in one go.
For more information, you could look into the ViewGroup - Android Documentation

Instead of hiding the view, try removing the unwanted views like
viewfliper.removeViewAt(relativeA POSITION);

Related

Make constraint layout untouchable

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.

Android: How to add Views from a different layout

I want to set a blank relativeLayout then start adding some views from another relativeLayout.
I want to do this because at the moment I have many bitmaps in a single layout which causes memory errors. So i want to achieve the effect of adding and removing views as I see fit in the code.
At the moment I am using the setContentView() of a layout on the onCreate() which causes me to have memory erros since there are too many views to add at once.
Another way. Perhaps it is possible to setContentView() of the layout with too many views. Only making it not adding any views before I code it to add specific views.
setContentView(R.layout.start_up_screen_denmark);
// This will add all the views in the layout causing a memory error. Making everything below irrelavant.
// So perhaps there is a way to set the ContentView without adding all the views automaticly.
// Perhaps i can set a blank layout and add views to that layout from the other layout at will.
ImageView denmark = (ImageView) findViewById(R.id.GoDenmark);
ViewGroup parent = (ViewGroup) denmark.getParent();
parent.removeView(denmark);
Using a LinearLayout might be better suited for what you're trying to do since you can easily add and remove views from a LinearLayout with lin_lay.addView(View child, int index) and lin_lay.removeViewAt(int index).
However, it also sounds like you might want to look into a RecyclerView if you have a lot of bitmaps in one layout and it's causing memory issues.

How to swap two LinearLayout

I have a parent Linear Layout inside which there are two Linear Layout and a button.Each Linear Layout inside the parent Linear layout has two items in it. Items include a edit text and a spinner.what I want is to swap this two LinearLayout when i click the button.So my question is How do i do that programatically?. I am new to Android development so please help me to solve this.
On your outermost LinearLayout, try calling removeViewAt(0). This should remove the first LinearLayout. Then call addView() passing it the first LinearLayout.
One simple way would be to just make two layouts. Designed such that when you are ready to use the other one, switch layouts and then set that as the current view.
Or you could do so with various animation classes if trying to get fancy with it. If there is an exact visual effect you are trying to receive, perhaps provide a bit more on what you want.
As Karim mentioned, you can use setVisibilty() to View.GONE and the to View.VISIBLE.
But for a smooth swapping you are going to need to learn about Translate Animation.
Here a working example of how to swap two views (e.g. two LinearLayouts):
ViewGroup root = findViewById(R.id.my_root);
// assumption: root has 2 child views only
// swap left and right (or top and bottom)
View leftView = root.getChildAt(0);
root.removeViewAt(0);
root.addView(leftView);
// now the two child views of root are swapped

Animation: Move TextView into another container

I want to move, in an anmiated way, a TextView in a LinearLayout into another LinearLayout.
However, I can't get it to move outside its container view (the LinearLayout it is in), it only moves inside this. Can someone help me to get this done? Also see the following image:
I'm using the NineOldAndroids library and have tried with the ViewPropertyAnimator:
animate(myTextView).setDuration(500).x(?).y(?);
And also with:
animate(myTextView).setDuration(500).translationX(?).translationY(?);
Instead of the '?' in above I want to be able to find out the position of the LinearLayout I want to drop the TextViews in. (If it's not possible to move to a certain View by stating the View-object).
What need to be done is to add "android:clipChildren="false"" to all the container layouts.

Graphical Layout shows first view of ViewFlipper, how to see others?

I am using Eclipse and a ViewFlipper. In Graphical Layout, I want to see the second, third, and forth layouts of my views - right now, I can only see the first view. Any suggestions?
If I'm understanding you correctly, you want to see each view in the 'Graphical layout' tool? The way I do this, is instead of having all the layout work done in one xml (where your viewflipper is) I make each view a new layout xml. And then have each view (xml file) included into the view flipper by using this....
<include
layout="#layout/layout_media"
android:id="#+id/flipper_media" />
Hope this helps.
just put each layout in relative layout or linear what ever you are working with then with each layout you will work with the first one in the order and etc.. then at the end put each layout in the order you want later
I had to subclass the ViewSwitcher class to display an indeterminate ProgressBar until data is ready to display in the second view. I used isInEditMode() to determine whether I was actually running the app or just previewing in AS.
You should be able to add a custom attribute to choose which child to display. This might look a bit overkill, but if you happen to already have to subclass your ViewSwitcher or ViewFlipper, i think it is not a big deal.
I will try to put an example later.

Categories

Resources