Android 自定义导航滑块

Android 自定义导航滑块,android,navigation-drawer,Android,Navigation Drawer,我正在尝试用android制作一个自定义导航抽屉。 它应该包含一个微调器视图,用于从列表中选择城市,然后选择城市温度,然后选择姓名、电子邮件和联系电话 我能够使城市选项和编辑的名称,电子邮件等文本列表。现在我不能在其中插入临时详细信息 需要帮助想想你怎么能做到!不管怎样,给你怎么做。首先在你的布局中做相对布局,称之为相对布局,比如说左抽屉。然后给新创建的布局一个颜色,基本上你可能想给白色,好的,下一步是给相对布局的高度 match_parent or fill_parent 布局的宽度应该是固

我正在尝试用android制作一个自定义导航抽屉。 它应该包含一个微调器视图,用于从列表中选择城市,然后选择城市温度,然后选择姓名、电子邮件和联系电话

我能够使城市选项和编辑的名称,电子邮件等文本列表。现在我不能在其中插入临时详细信息


需要帮助

想想你怎么能做到!不管怎样,给你怎么做。首先在你的布局中做相对布局,称之为相对布局,比如说左抽屉。然后给新创建的布局一个颜色,基本上你可能想给白色,好的,下一步是给相对布局的高度

match_parent or fill_parent

布局的宽度应该是固定的……或者,如果你想让抽屉从屏幕的开始一直到屏幕的结束,你仍然可以使用上面写的代码。所以,在所有这些之后,你所要做的就是在你创建的布局上放一个按钮(最有用的按钮是ToggleButton,因为它有两种状态需要按下(开/关))该按钮将使您创建的布局变为可见或不可见,因此这里有一个自定义的滑动抽屉,您可以在其中放置任何您喜欢的小部件,并在其上放置一些翻译动画,使其成为真正的抽屉。祝您好运,想想您如何实现这一点!不管怎样,给你怎么做。首先在你的布局中做相对布局,称之为相对布局,比如说左抽屉。然后给新创建的布局一个颜色,基本上你可能想给白色,好的,下一步是给相对布局的高度

match_parent or fill_parent

布局的宽度应该是固定的……或者,如果你想让抽屉从屏幕的开始一直到屏幕的结束,你仍然可以使用上面写的代码。所以,在所有这些之后,你所要做的就是在你创建的布局上放一个按钮(最有用的按钮是ToggleButton,因为它有两种状态需要按下(开/关))该按钮将使您创建的布局变为可见或不可见,因此这里有一个自定义的滑动抽屉,您可以在其中放置任何您喜欢的小部件,并在其上放置一些翻译动画,使其成为真实的抽屉。祝您好运

关闭滑块的动画

public static void playcloseanimationofleftdrawer() {
        TranslateAnimation translateAnimation = new TranslateAnimation(
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
                TranslateAnimation.RELATIVE_TO_SELF, -1.0f,
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f);
        translateAnimation.setInterpolator(new DecelerateInterpolator(2.0f));
        AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f);
        AnimationSet animation = new AnimationSet(false);
        animation.addAnimation(translateAnimation);
        animation.addAnimation(alphaAnimation);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                // Do nothing
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                // Do nothing
            }

            @Override
            public void onAnimationEnd(Animation animation) {

            }
        });
        animation.setDuration(500);
        leftdrawer.startAnimation(animation);


    }
 public static void playopenanimationleftdrawer() {
        TranslateAnimation translateAnimation = new TranslateAnimation(
                TranslateAnimation.RELATIVE_TO_SELF, -4.0f,
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f);
        translateAnimation.setInterpolator(new DecelerateInterpolator(2.0f));
        AlphaAnimation alphaAnimation = new AlphaAnimation(0.0f, 1.0f);
        AnimationSet animation = new AnimationSet(false);
        animation.addAnimation(translateAnimation);
        animation.addAnimation(alphaAnimation);
        animation.setDuration(1000);
        animation.setFillAfter(true);
        leftdrawer.startAnimation(animation);
    }
打开滑块的动画

public static void playcloseanimationofleftdrawer() {
        TranslateAnimation translateAnimation = new TranslateAnimation(
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
                TranslateAnimation.RELATIVE_TO_SELF, -1.0f,
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f);
        translateAnimation.setInterpolator(new DecelerateInterpolator(2.0f));
        AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f);
        AnimationSet animation = new AnimationSet(false);
        animation.addAnimation(translateAnimation);
        animation.addAnimation(alphaAnimation);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                // Do nothing
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                // Do nothing
            }

            @Override
            public void onAnimationEnd(Animation animation) {

            }
        });
        animation.setDuration(500);
        leftdrawer.startAnimation(animation);


    }
 public static void playopenanimationleftdrawer() {
        TranslateAnimation translateAnimation = new TranslateAnimation(
                TranslateAnimation.RELATIVE_TO_SELF, -4.0f,
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f);
        translateAnimation.setInterpolator(new DecelerateInterpolator(2.0f));
        AlphaAnimation alphaAnimation = new AlphaAnimation(0.0f, 1.0f);
        AnimationSet animation = new AnimationSet(false);
        animation.addAnimation(translateAnimation);
        animation.addAnimation(alphaAnimation);
        animation.setDuration(1000);
        animation.setFillAfter(true);
        leftdrawer.startAnimation(animation);
    }

关闭滑块的动画

public static void playcloseanimationofleftdrawer() {
        TranslateAnimation translateAnimation = new TranslateAnimation(
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
                TranslateAnimation.RELATIVE_TO_SELF, -1.0f,
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f);
        translateAnimation.setInterpolator(new DecelerateInterpolator(2.0f));
        AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f);
        AnimationSet animation = new AnimationSet(false);
        animation.addAnimation(translateAnimation);
        animation.addAnimation(alphaAnimation);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                // Do nothing
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                // Do nothing
            }

            @Override
            public void onAnimationEnd(Animation animation) {

            }
        });
        animation.setDuration(500);
        leftdrawer.startAnimation(animation);


    }
 public static void playopenanimationleftdrawer() {
        TranslateAnimation translateAnimation = new TranslateAnimation(
                TranslateAnimation.RELATIVE_TO_SELF, -4.0f,
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f);
        translateAnimation.setInterpolator(new DecelerateInterpolator(2.0f));
        AlphaAnimation alphaAnimation = new AlphaAnimation(0.0f, 1.0f);
        AnimationSet animation = new AnimationSet(false);
        animation.addAnimation(translateAnimation);
        animation.addAnimation(alphaAnimation);
        animation.setDuration(1000);
        animation.setFillAfter(true);
        leftdrawer.startAnimation(animation);
    }
打开滑块的动画

public static void playcloseanimationofleftdrawer() {
        TranslateAnimation translateAnimation = new TranslateAnimation(
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
                TranslateAnimation.RELATIVE_TO_SELF, -1.0f,
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f);
        translateAnimation.setInterpolator(new DecelerateInterpolator(2.0f));
        AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f);
        AnimationSet animation = new AnimationSet(false);
        animation.addAnimation(translateAnimation);
        animation.addAnimation(alphaAnimation);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                // Do nothing
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                // Do nothing
            }

            @Override
            public void onAnimationEnd(Animation animation) {

            }
        });
        animation.setDuration(500);
        leftdrawer.startAnimation(animation);


    }
 public static void playopenanimationleftdrawer() {
        TranslateAnimation translateAnimation = new TranslateAnimation(
                TranslateAnimation.RELATIVE_TO_SELF, -4.0f,
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f,
                TranslateAnimation.RELATIVE_TO_SELF, 0.0f);
        translateAnimation.setInterpolator(new DecelerateInterpolator(2.0f));
        AlphaAnimation alphaAnimation = new AlphaAnimation(0.0f, 1.0f);
        AnimationSet animation = new AnimationSet(false);
        animation.addAnimation(translateAnimation);
        animation.addAnimation(alphaAnimation);
        animation.setDuration(1000);
        animation.setFillAfter(true);
        leftdrawer.startAnimation(animation);
    }

发布你已经做过的事情。发布你已经做过的事情。欢迎回复。但在我的主要活动中,我会隐藏操作栏,并通过点击框架内的文本(而不是应用程序标题)来打开抽屉。在创建自己的布局时,您可以做任何您想做的事情,所以请将按钮放在任何您想让我做的地方。您能帮我打开和关闭MainActivity中的自定义布局吗。只需像这样执行VISIBLIE和INVISIBLE YourLayout.setVisibility(View.INVISIBLE),如果您想在单击时使其可见,请使用visible参数执行相同操作谢谢您的回复。但在我的主要活动中,我会隐藏操作栏,并通过点击框架内的文本(而不是应用程序标题)来打开抽屉。在创建自己的布局时,您可以做任何您想做的事情,所以请将按钮放在任何您想让我做的地方。您能帮我打开和关闭MainActivity中的自定义布局吗。只需像这样执行VISIBLIE和INVISIBLE YourLayout.setVisibility(View.INVISIBLE),如果要使其在单击时可见,请使用visible参数执行相同操作