问题
is it possible to have structure like the one below. And have LinearLayout that is at front to be off screen:
<FrameLayout>
<LinearLayout>
.. Back Layout
</LinearLayout>
<LinearLayout>
.. Front layout
</LinearLayout>
</FrameLayout>
Here is the image.
What I have tried: I have tried setting android:layout_marginLeft="-300dp" for LinearLayout A (front), but as soon as I test it on my phone the A layout is back inside of visible area. I have also tried pushing the A layout off the screen with TranslateAnimation, after animation ends A layout is back inside of visible area.Please help me solve the problem. Thank you.
回答1:
So in case anyone needs something like this here how I solved it. Sliding menu on top of content. Layout structure as described in the question. Here is a simple animation in xml: show_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="-100%"
android:toXDelta="0%"
android:duration="400">
</translate>
</set>
hide_menu.xml:
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="0%"
android:toXDelta="-100%"
android:duration="400">
</translate>
</set>
in MyActivity
//loading hide animation and setting listener.
anim = AnimationUtils.loadAnimation(this, R.anim.hide_menu);
anim.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
//on animation end setting visibility to gone
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
MenuList.setVisibility(View.GONE);
}
});
Same thing is done for animation for show_menu animtaion except it would have onAnimationStart setting visibilty to visible. MenuList in the code is A layout from the figure in the question.
Update: *The best way to do a sliding menu today is to use the DrawerLayout.*
来源:https://stackoverflow.com/questions/16338647/framelayout-is-it-possible-to-put-child-layout-off-screen