我怎样才能让一个下拉菜单隐藏 [英] How can I make a drop down hidden menu

查看:327
本文介绍了我怎样才能让一个下拉菜单隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打一个下拉菜单,就像一个状态菜单,这是隐藏在活动开始时,当它的pressed或滑动它打开如下图所示。

图片

http://i.stack.imgur.com/jeq5z.png

我的布局目前已形成的RelativeLayout为顶级酒吧和滚动型对那些之间的文本..,我希望把菜单。

我不这样做的PhoneGap的或类似的东西,只是Java和XML这个应用程序。

在此先感谢

修改
谢谢大家的帮助!我最终会做已设置了屏幕与translationY一个的FrameLayout,然后,点击后,只需上下滑动..这里的剪断..我就离开这里,以防别人需要它。

上layout.xml

 <的FrameLayout
    机器人:ID =@ + ID / layout_FrameLayout
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:背景=#00FFFFFF>
        <! - STUF - >
< /&的FrameLayout GT;

上activity.java

 私人的FrameLayout statusDrawer = NULL;
私人诠释statusDrawerHeight; //将的FrameLayout的高度(自动生成)
私人INT statusDrawerDragButtonHeight = 30 + 5; //边框的DragButton +高的高度
私人布尔statusDrawerOpened = FALSE;
私人INT statusDrawerDuration = 750; //时间(毫秒)
私人TimeInterpolator插= NULL; //动画类型see@developer.android.com/reference/android/animation/TimeInterpolator.html@覆盖
保护无效onCreated(捆绑savedInstanceState){
    statusDrawer =(的FrameLayout)findViewById(R.id.layout_FrameLayout);
    内插器=新AccelerateDecelerateInterpolator();    statusDrawer.post(新的Runnable(){
        @覆盖
        公共无效的run(){
            statusDrawerHeight = statusDrawer.getHeight();
            statusDrawer.setTranslationY(-statusDrawerHeight + statusDrawerDragButtonHeight);
        }
    });    statusDrawer.setOnClickListener(新OnClickListener(){
        @覆盖
        公共无效的onClick(视图v){
            如果(statusDrawerOpened){
                statusDrawer.animate()
                  .translationY(-statusDrawerHeight + statusDrawerDragButtonHeight)
                  .setDuration(statusDrawerDuration)
                  .setInterpolator(插值)
                  。开始();
            }其他{
                statusDrawer.animate()
                  .translationY(0)
                  .setDuration(statusDrawerDuration)
                  .setInterpolator(插值)
                  。开始();
            }
            !statusDrawerOpened = statusDrawerOpened;
        }
    });
}


解决方案

使用的FrameLayout 作为根布局。添加的下拉菜单布局在画面的右侧。呼叫

  menuView.setTranslationY(-view.getHeight);

这个观点最初隐藏在下拉菜单中,当活动开始。确保 menuView 只是指不降小标签按钮查看一部分。当用户触摸标签动画 translationY 0,这样的布局会滑下

  ObjectAnimator.ofFloat(dropDownView,translationY,-view.getHeight,0).setDuration(200)。开始();

dropDownView 指的是完整的下拉菜单。

使用 ObjectAnimator 需要API级别11.如果你需要支持旧的API级别,使用的http://developer.android.com/reference/android/view/animation/TranslateAnimation.html (其中有一些下降侧)。

如果您想要,而不是增加一个滑动效果,例如滑动菜单正在一起用手指,安装 OnTouchListener

  dropDownTab.setOnTouchListener(新OnTouchListener(){
    公共无效onTouch(视图V,MotionEvent五){
        //使下拉菜单手指跟随手指的位置。
        //再次使用dropDownView.setTranslationY(...),以移动视图。
        //如果下拉菜单已经拖了一定的距离,使其本身使用上述动画搬走。
    }
});

I want to make a drop down menu, like a status menu, that is hidden when the activity starts, and when it's pressed or slid it opens like the image below..

http://i.stack.imgur.com/jeq5z.png

My layout currently has a RelativeLayout for the top bar and a ScrollView for the text.. between those, i'd like to put the menu..

I'm not doing this app on phonegap or anything like that, just java and xml..

Thanks in advance

Edit: Thank you all for your help! I end up doing a FrameLayout that was set off the screen with the translationY and then, when clicked, just slide up and down.. Here's the snipped.. I'll just leave it here in case someone else needs it.

on layout.xml

<FrameLayout
    android:id="@+id/layout_FrameLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#00ffffff" >
        <!-- stuf -->
</FrameLayout>

on activity.java

private FrameLayout statusDrawer = null;
private int statusDrawerHeight; // height of the FrameLayout (generated automatically)
private int statusDrawerDragButtonHeight = 30 + 5; //height of the DragButton + height of the border
private boolean statusDrawerOpened = false;
private int statusDrawerDuration = 750; //time in milliseconds 
private TimeInterpolator interpolator = null; //type of animation see@developer.android.com/reference/android/animation/TimeInterpolator.html

@Override
protected void onCreated(Bundle savedInstanceState){
    statusDrawer = (FrameLayout) findViewById(R.id.layout_FrameLayout);
    interpolator = new AccelerateDecelerateInterpolator();

    statusDrawer.post(new Runnable() {
        @Override
        public void run() {
            statusDrawerHeight = statusDrawer.getHeight();
            statusDrawer.setTranslationY(-statusDrawerHeight+statusDrawerDragButtonHeight);
        }
    });

    statusDrawer.setOnClickListener(new OnClickListener(){
        @Override
        public void onClick(View v){
            if(statusDrawerOpened) {
                statusDrawer.animate()
                  .translationY(-statusDrawerHeight+statusDrawerDragButtonHeight)
                  .setDuration(statusDrawerDuration)
                  .setInterpolator(interpolator)
                  .start();
            } else {
                statusDrawer.animate()
                  .translationY(0)
                  .setDuration(statusDrawerDuration)
                  .setInterpolator(interpolator)
                  .start();
            }
            statusDrawerOpened = !statusDrawerOpened;
        }
    });
}

解决方案

Use a FrameLayout as the root layout. Add the drop menu layout as in the right side of your picture. Call

menuView.setTranslationY(-view.getHeight);

on this view to initially hide the drop down menu when the activity is started. Make sure menuView only refers to the drop down view part without the small tab button. When the user touches the tab animate translationY to 0 so that the layout will slide down

ObjectAnimator.ofFloat(dropDownView, "translationY", -view.getHeight, 0).setDuration(200).start();

whereby dropDownView refers to the complete drop down menu.

Using ObjectAnimator requires API level 11. If you need to support older API levels, use http://developer.android.com/reference/android/view/animation/TranslateAnimation.html (which has some down sides).

If you instead want add a sliding effect, e.g. the sliding menu is moving with together with the finger, install a OnTouchListener:

dropDownTab.setOnTouchListener(new OnTouchListener() {
    public void onTouch(View v, MotionEvent e) {
        // Make the drop down menu finger follow the finger position.
        // Use again dropDownView.setTranslationY(...) to move the view.
        // If the drop down menu has been dragged a certain distance, make it move out by itself using the animation as above.
    }
});

这篇关于我怎样才能让一个下拉菜单隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆