在Android的自定义视图按钮面板 [英] Button Panel on the custom View in android

查看:144
本文介绍了在Android的自定义视图按钮面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个按钮面板,提供游戏选项的球员。此板具有向进出画布的滑动,如下面的图

I want to create a button panel that provides game options to the player. This panel has to slide in and out of the canvas as shown in the figure below.

什么样的​​方法我可以借此实现这一点。我可以使用正常的按键?
 任何例子是AP preciated。

What approaches can I take to implement this. Can I use normal buttons? Any examples would be appreciated.

谢谢
帕特

推荐答案

首先是你可以使用正常的按键让您在与放幻灯片;出面板。现在,该怎么办呢?

First of all yes you can use normal button for your slide in & out panel. Now, how to do it?

首先为你面板创建一个单独的布局xml文件如 panel.xml

First of all create a separate layout xml file for you panel e.g. "panel.xml".

现在使用包含标签在你的游戏xml文件,并将其设置的比重:TOP 知名度:GONE 并设置它的ID,以面板即

Now use the include tag in your game xml file and set it's gravity : TOP and visibility : GONE and set it's id to panel i.e.

android:id="@+id/panel";

现在创建一个文件夹名为动画里面你的项目的资源文件夹中。在这里,创建两个XML文件slide_in.xml&安培; slide_out.xml这些XML苍蝇将帮助您获得幻灯片在&放大器;出来的效果。 code这些XML文件如下

Now create a folder named "anim" inside your projects res folder. Here create two xml files slide_in.xml & slide_out.xml these xml flies will help you in getting the slide in & out effect. Code for these xml file is as follow

slide_in.xml:

slide_in.xml:

<?xml version="1.0" encoding="utf-8"?>
    <translate xmlns:android="http://schemas.android.com/apk/res/android"
     android:fromYDelta="-100%p" 
     android:toYDelta="0%p"
     android:duration="3000"/>

slide_out.xml:

slide_out.xml:

<?xml version="1.0" encoding="utf-8"?>
    <translate xmlns:android="http://schemas.android.com/apk/res/android"
     android:fromYDelta="0%p" 
     android:toYDelta="-100%p"
     android:duration="3000"/>

现在要求所有的事情构建您的幻灯片中和放大器;从面板已经准备就绪。

Now all the things required to build your slide in & out panel are ready.

实施

请注意:保持一个布尔变量的 isPanelVisible 以保持面板的可见性状态的检查

NOTE: maintain a boolean variable isPanelVisible to keep check of visibility state of the panel.

创建两个动画类对象的的slideIn &安培; 滑出和一个视图类对象的作为我们包含在游戏中的XML文件的panel.xml,然后初始化它们是这样的:

Create two Animation class object slideIn & slideOut and one View class object panel for the panel.xml which we included in the game xml file, then initialize them like this:

Animation slideIn= AnimationUtils.loadAnimation(getApplicationContext(),
            R.anim.slide_in);
Animation slideOut= AnimationUtils.loadAnimation(getApplicationContext(),
            R.anim.slide_out);
View panel = findViewById(R.id.panel);

现在,当在用户单击按钮来显示和放幻灯片;出onClickListener()方法中板做这样的事情:

Now when the user clicks on the button to show the slide in & out panel inside the onClickListener() method do something like this:

if(isPanelVisible){
    isPanelVisible = false;
    panel.startAnimation(slideOut);
    panel.setVisibility(View.Gone);
} else{
    isPanelVisible = true;
    panel.startAnimation(slideIn);
    panel.setVisibility(View.Visible);
}

这篇关于在Android的自定义视图按钮面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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