How to reset widget layout inside a view layout during device rotation? - android

Well, i am developing new features inside a product which means lots of limitations i just can't break.
There is one activity which monitor the rotation event but use one unified layout for both portrait and landscape. Now i need to add some animations for several widgets inside the view.
For example, animation A to expand a toolbar, while B to collapse it.
But when i do A in landscape mode, and then rotate to portrait mode, the widgets still keep the position after animation A instead of the original layout configured in the xml file.
So what i want is to reset the layout partially. How can i achieve it???
Thanks!

Finally, i found a solution. Well may be not the best, it still solve my problem.
Insert a parent layout inside the activity view, let's say and put nothing inside it.
During the run time, add the child view according to the screen orientation dynamically as following:
Put the codes inside the onConfigurationChanged().
LinearLayout ll = (LinearLayout)findViewById(R.id.linearlayoutId);
View viewPor/viewLand = getLayoutInfalter().Infalte(R.layout.Por/Land, null);
ll.addView(viewPor/viewLand);
You may need a object associated with the specific view for manipulating the widgets inside the view for the animations.

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.

Setting the visibility for a linear layout(view group)

When I set setVisibility(View.GONE) or setVisibility(View.VISIBLE) for a linear layout it seems that it does not changes the visibility of the view(saying view group would be more accurate). At various post in SO, it has been suggested that get the count for the particular linear layout and change the visibility of each child one by one. Well that can work but it also increases the time taken to process that piece of code. And when there are various view involve, it will be increase to many folds. Same goes for setEnabled(true) or setEnabled(false).
My question is there a alternative for this, as directly changing the visibility is definitely not working? And if not can anybody explain to me why android choose to keep it this way, i.e developer cannot directly change the state(visibility/enabling) of the view group.

Android draw outside the view

I would work with a piece of layout that isn't shown, the user must scroll to see what I have did. How can I do it? Can I join 2 different layout in one? I prefer to collocate item as I do with default layout. If it can help, I use Android studio. I prefer use elements without code, adding them from palette. An example :
You can use two different layout in main relative layout & whenever u want child layout just set visibility.
You will want to use a ScrollView for this. From the documentation:
Layout container for a view hierarchy that can be scrolled by the user, allowing it to be larger than the physical display.

Android Listview combined with textView fields

i have some issues to get by.
In portrait orientation i need simple listView with individual button for each row.
In landscape orientation i need to divide view for two areas. First (let's say at left) is ListView mentioned before. Second area contains few TextViews filled after clicking on ListView.
Questions:
To differ between land and portrait orientation i'm going to use layout-land and layout-port folders. But in lanscape orientation there will be few additional controls. Checking orientation in onCreate method and not initializing additional controls will be enough?
How to get described above landscape orientation view?
Thakns in advance.
You can do it the way you mentioned. Another possibility is to include all of the elements in both layouts, but in the portrait orientation you can hide some of them (by setting width/height to 0, or by setting android:visibility to 2 (gone)).
You can use a horizontal LinearLayout to get two side-by-side regions. The first child of the LinearLayout will be your ListView. The second child of the LinearLayout can contain the extra TextViews you want.
you need not check orientation in onCreate method as because android operating system will load entire activity when the orientation changes.
you need to do only one thing. for the UI give same id's in both landscape and portrait xml files.that's enough
I think that the use of Fragments is fit for the layout you want to achieve.
Here is a link to a tutorial that you may find useful.
http://mobile.tutsplus.com/tutorials/android/android-sdk_fragments/
Hope that helps. :)

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