求大神赐教,关于android的跳转页面问题,设置了3个button分别跳转到不同的页面。
我在Eclipse上新建了一个Android文档,在layout里设置了四个页面,分别是activity_main,activity2,activity3,test.这四个页面分别对应src下的MainActivity,TweenActivity,Framectibity,test.之后下面会附上详细的代码,求大神们帮忙看一下我这段代码究竟哪里出问题了,才导致点击test按钮跳转时产生模拟器崩溃的原因。
首先是layout中的activity_main 以及 MainActivity.
activity_main:
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="73dp"
android:text="Tween" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_centerVertical="true"
android:text="Frame" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button2"
android:layout_alignLeft="@+id/button2"
android:layout_alignRight="@+id/button2"
android:text="test" />
</RelativeLayout>
MainActivity:[b][/b]
package com.example.woaimeinv;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
//定义控件
Button tween;
Button frame;
Button test;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//绑定资源
tween=(Button)findViewById(R.id.button1);
frame=(Button)findViewById(R.id.button2);
test=(Button)findViewById(R.id.button3);
//声明按钮监听时间
tween.setOnClickListener(btnlistener);
frame.setOnClickListener(btnlistener);
test.setOnClickListener(btnlistener);
}
//监听事件
private OnClickListener btnlistener=new OnClickListener(){
@Override
public void onClick(View v) {
// TODO 自动生成的方法存根
if(v.getId()==R.id.button1){
//新建Intent,页面切换
Intent intent=new Intent();
intent.setClass(MainActivity.this,TweenActivity.class);
startActivity(intent);
}
else if(v.getId()==R.id.button2){
Intent intent=new Intent();
intent.setClass(MainActivity.this,Framectivity.class);
startActivity(intent);
}
else{
Intent intent=new Intent();
intent.setClass(MainActivity.this,test.class);
startActivity(intent);
}
}
};
}
/*@Override
public void onClick(View m) {
// TODO Auto-generated method stub
if(m.getId()==R.id.button1){
//新建Intent,页面切换
Intent intent=new Intent();
intent.setClass(MainActivity.this,TweenActivity.class);
startActivity(intent);
}
else{
Intent intent=new Intent();
intent.setClass(MainActivity.this,Framectivity.class);
startActivity(intent);
//overridePendingTransition(R.anim.hyperspace_in, R.anim.hyperspace_out);
}*/
//}
activity2:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<Button
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BEGIN" />
<Button
android:id="@+id/Button02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="14dp"
android:text="STOP" />
</LinearLayout>
[u]TweenActivity:[/u]
package com.example.woaimeinv;
import android.app.Activity;
import android.os.Bundle;
public class TweenActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO 自动生成的方法存根
super.onCreate(savedInstanceState);
setContentView(R.layout.activity2);
}
}
activity3main:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Alpha" />
<Button
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Scale" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Translate" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rotate" />
</LinearLayout>
Framectivity:
package com.example.woaimeinv;
import android.app.Activity;
import android.os.Bundle;
public class Framectivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO 自动生成的方法存根
super.onCreate(savedInstanceState);
setContentView(R.layout.activity3);
}
}
test:(layout下)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
test:(src下)
package com.example.woaimeinv;
import android.app.Activity;
import android.os.Bundle;
public class test extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO 自动生成的方法存根
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
}
}
androidManifest:(注册表)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.woaimeinv"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.woaimeinv.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".TweenActivity"
android:configChanges="orientation|keyboardHidden"
></activity>
<activity android:name=".Framectivity"
android:configChanges="orientation|keyboardHidden"
></activity>
<activity android:name=".test"
android:configChanges="orientation|keyboardHidden"
></activity>
</application>
</manifest>
[解决办法]
/*@Override
public void onClick(View m) {
// TODO Auto-generated method stub
if(m.getId()==R.id.button1){
//新建Intent,页面切换
Intent intent=new Intent();
intent.setClass(MainActivity.this,TweenActivity.class);
startActivity(intent);
}
else{
Intent intent=new Intent();
intent.setClass(MainActivity.this,Framectivity.class);
startActivity(intent);
//overridePendingTransition(R.anim.hyperspace_in, R.anim.hyperspace_out);
}*/
//}
这个函数是重复了,上面的监听时间类以及定义了点击事件,这里没有对test的button家事件
[解决办法]