【发布时间】:2014-04-27 01:16:09
【问题描述】:
由于我是 android 新手,我编写了一个代码,其中包含一个按钮,该按钮必须设置动画并链接到另一个 xml 文件。但是当我编译它时,按钮会动画,但不会链接到其他文件。当我点击它时,我需要动画按钮进入另一个 xml 页面。
代码和图片展示如下
button.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bulbasaur"
tools:context=".MainActivity" >
<Button
android:id="@+id/enter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="58dp"
android:onClick="onEnterClicked"
android:text="@string/enter_button" />
</RelativeLayout>
/res/anim/anim_alpha.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator">
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.1"
android:duration="500"
android:repeatCount="1"
android:repeatMode="reverse" />
</set>
MainActivity.java
package com.coded.sandeep;
import com.coded.sandeep.SecondActivity;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Animation animAlpha2 = AnimationUtils.loadAnimation(this, R.anim.anim_alpha);
Button btnEnter = (Button)findViewById(R.id.enter);
btnEnter.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg1) {
arg1.startAnimation(animAlpha2); //when i click the button animation is working
but onEnterClicked is not working can anyone
help me to edit the code here such that both
animation and link to another xml page works
}}); }
public void onEnterClicked(View view)
{
startActivity(new Intent(getApplication(),SecondActivity.class));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true; }}
任何人都可以帮助我如何同时包含 onEnterclicked 和动画,以便按钮将动画然后转到我在 secondActivity.java 中声明的其他 xml 文件(在程序中声明)
如果我删除 onenterclicked 函数上方的动画代码将起作用,但两者都不起作用,我需要两者都起作用
解决我的问题我尝试了很多方法来合并代码,但有时我会出错。
【问题讨论】:
标签: java android xml animation