I found this code to make a sliding menu like facebook app. He (who wrote this code) used a FrameLayout to contain 2 views and used TranslateAnimation to show/hide menu. He used setFillAfter(true) to keep position of view. In onAnimationEnd, he used view.layout(left, top, right, bottom) to ensure that views are in correct position.
I modified this code to use with 3 views: leftView, centerView and rightView (Each view in my case is a LinearLayout) like facebook and found a problem: when activity is show leftView (and a part of centerView), if I click an EditText in leftView and soft keyboard is shown, it return to centerView. Similarly, it happens when I click on an ExpandableListView and Childs is shown.
Can anyone help me please?. Here is [my code](https://dl.dropbox.com/u/38205395/TestErrorSlidingActivity.rar).
Thank you in advance and sorry for my poor English!
Your problem is that the keyboard retriggers the measurement/layout pass of your FrameLayout.
At this point the layout you manually called gets replaced from the FrameLayout original layout.
To avoid this you have 2 ways:
1) Do not use a FrameLayout (define your own extension of the viewgroup or extend FrameLayout overriding all the methods regarding the measurement/layout of the children)
2) Do not call layout after the animation but rather try using setMargin on your children (if possible)
Obviously the best way would be the first one.
Try using android:windowSoftInputMode="adjustNothing" for activity in manifest.
Worked for me :)
Related
I'm looking for a way to display a "stand-by screen" for within my app.
I have a main activity with a fragment and I've added a button to the side of the main activity to trigger when this "Stand-by" screen should show, which will be nothing more than displaying a picture.
I have already tried changing the content view, it works for setting the screen but when I try set it back to activity_main it throws an error about being unable to inflate the fragment.
Which lead me to try creating a linearlayout view programmatically (spelling?) and setting this view visible with setvisibility but this doesn't work either.
I have also looked at AlertDialog but I don't think this is the best way to do this.
Thank you for reading
The easiest? add an ImageView or any View with opaque background as the last element of your layout, with dimensions MATCH_PARENT / MATCH_PARENT and Visibility GONE.
When you want to show it, just call view.setVisibility(View.VISIBLE) , or view.setVisiblity(View.GONE) to hide it. It will come up above the rest of elements, which will be hidden under its opaque background.
View view=findViewById(R.id.yourSplashId);
show
view.setVisibility(View.VISIBLE);
hide
view.setVisibility(View.GONE);
I see in your question that you tried this approach and it didn't work. Maybe that View you generated was behind the fragment?
You can also put your Fragment + splash inside a ViewFlipper
<ViewFlipper>
<fragment>...</fragment>
<FrameLayout>
<imageView>
<progressbar> .. etc
</FrameLayout>
</ViewFlipper>
this has the added benefit that you can setup animations for transitions etc.. In this case:
ViewFlipper myFlipper=findViewById(R.id.myFlipper);
myFlipper.setDisplayedChild(0); // fragment
myFlipper.setDisplayedChild(1); // splash
and
myFlipper.setInAnimation(AnimationUtils.loadAnimation(v.getContext(), R.anim.left_in));
myFlipper.setOutAnimation(AnimationUtils.loadAnimation(v.getContext(), R.anim.right_out));
How to get floating listview on top of another activity like in android facebook app.I tried to do it but I dont know how to proceed .
I am trying to create listview with toggle imagebutton on top which displays listview with linear fade down animation over already existing view .Here is a link to what I am talking about
(source: handytechplus.com)
Rally appreciate any help or seek clarity in the above question.
Thanks in Advance.
My suggestion would be using a custom ListFragment, sitting on top of your data.
As RelativeLayout works, the lower the item is in your xml, the higher its Z-axis will be.
Create a new class extending ListFragment, put it in the XML.
when you want the layout closed, just set the visibility of the View (Fragment) to "gone" and vise-versa.
About the animation, check the Android developer site about changing visibility animation.
EDIT:
About creating Fragment and implementing in the XML : http://developer.android.com/training/basics/fragments/creating.html
To change visibility :
((CustomFragment)getSupportFragmentManager().findFragmentById(R.id.your_fragment)).setVisibility(View.GONE);
Make sure you use FragmentActivity as your activity and support4.ListFragment instead of the regular ListFragment.
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);
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...
I want to display a recursive or nested text view at depth of 3 in Android.The text to be displayed is, dynamic coming from web service.
for example:
If I Click on Help(Level 1)
it'll show topics under Help
If I Click on Help_Topic_1(Level 2)
it'll show questions under Help_Topic_1
If I click on this question, say HT_Question_1(Level 3)
it'll show Answer of that question(Level 3)
how to accomplish with this? please guide me.
You should use ExpandableListView. Reference http://developer.android.com/reference/android/widget/ExpandableListView.html
You can call expandGroup and collapseGroup methods for expanding and collapsing on clicks.
the simplest way to do this is to have a nested layout structure. Your root view will contain the button to show level 1 and a child layout and initially be visible. The children's layout visibility will initially be set to "GONE". In the onclick listener for each button you change the visibility of the layout below it to view to "VISIBLE".
This of course is a very simple way of doing it. If you require to have open and close animations you'll need to use a more complex method.