让后按一下按钮在Android的布局出现动画 [英] Make a layout appear with animation after button click in Android
问题描述
我想实现一个简单的登录屏幕,一些文本和登录按钮,将默认情况下,点击登录按钮,一个新的框架布局后显示会出现从底部到顶部,并提示用户输入自己的用户名和密码!我可以做动画,这将覆盖从一个父到另一个但只针对单一对象,如按钮。
I'm trying to implement a simple login screen where some text and a login button will be displayed by default and after clicking the login button a new frame layout will appear from bottom to top and prompt user to enter their username and password! I can make animation which will overlay from one parent to another but only for single objects like buttons.
推荐答案
第一套无形
来布局。
设置动画效果基本show和了slideDown。
First set invisible
to your layout.
Set animation to slideUp and slideDown.
final LinearLayout layout = (LinearLayout)findViewById(R.id.yourlayout);
button.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
Animation slideUp = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_up);
Animation slideDown = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_down);
if(layout.getVisibility()==View.INVISIBLE){
layout.startAnimation(slideUp);
layout.setVisibility(View.VISIBLE);
}
});
slide_up.xml (创建 RES /阿尼姆
目录)
slide_up.xml (create in res/anim
directory)
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:fromYDelta="500" android:duration="500"/>
</set>
slide_down.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:fromYDelta="0" android:toYDelta="500" android:duration="500"/>
</set>
注意:
你应该在编辑值 slide_down.xml
和 slide_up.xml
,直到获得有利的结果 - 例如:变更安卓fromYDelta =500
到安卓fromYDelta =700
Note:
You should edit values in slide_down.xml
and slide_up.xml
until get favorable result.
for example:change android:fromYDelta="500"
to android:fromYDelta="700"
这篇关于让后按一下按钮在Android的布局出现动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!