【发布时间】:2011-04-26 07:05:39
【问题描述】:
我是安卓新手。在谷歌搜索了一下后,我尝试了一个动画程序并在模拟器中强制关闭,并且在运行项目时没有显示任何东西
我想为两个布局(xml 文件)(即 signin.xml 和 register.xml)设置翻转/翻转效果。通过单击 signin.xml 中的新用户按钮,我想将布局转换为 register.xml
我采用了两种布局并尝试实现,即线性和表格布局。我遵循的程序是否正确
我添加了单个按钮进行试用,但它不起作用,我想知道这段代码有什么问题
我没有收到任何错误,但运行时模拟器出现问题。
请有人帮助我,...谢谢!
这些是我的 xml 文件
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/Layout01"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
xmlns:android="http://schemas.android.com/apk/res/android" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" android:background="@drawable/loginapp">
<Button android:layout_width="49px" android:layout_height="44px" android:background="@drawable/login_home_btn_over_green" android:id="@+id/widget38"></Button>
</LinearLayout>
<RelativeLayout android:id="@+id/relativeLayout1" android:gravity="center" android:layout_marginTop="25dip" android:layout_height="177dip" android:background="@drawable/login_form_bg_green" android:layout_width="296dip">
<EditText android:layout_marginRight="0dip" android:id="@+id/userNameBox" android:layout_width="200px" android:background="@android:drawable/editbox_background" android:maxLines="1" android:layout_marginLeft="85dip" android:inputType="text" android:layout_height="wrap_content"></EditText>
<EditText android:layout_marginRight="0dip" android:id="@+id/passwordBox" android:layout_width="200px" android:background="@android:drawable/editbox_background" android:maxLines="1" android:layout_marginTop="45dip" android:layout_marginLeft="85dip" android:inputType="text|textVisiblePassword" android:layout_height="wrap_content"></EditText>
</RelativeLayout>
<LinearLayout android:id="@+id/ll_three" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_below="@+id/ll_two" android:gravity="center">
<Button
android:text="Sign In"
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_marginTop="5dip"
android:layout_marginRight="15dip"
android:layout_height="wrap_content"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginTop="5dip"
android:id="@+id/Button02"
android:text="New user"/>
</LinearLayout>
</LinearLayout>
注册.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout android:id="@+id/Layout02"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="0"
xmlns:android="http://schemas.android.com/apk/res/android">
<TableRow>
<TextView android:id="@+id/TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" REGISTER:"/>
</TableRow>
<TableRow>
<TextView android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Name:"/>
<EditText android:layout_marginRight="0dip"
android:id="@+id/userNameBox" android:background="@android:drawable/editbox_background"
android:maxLines="1" android:layout_marginLeft="15dip" android:layout_weight="1"
android:inputType="text" android:layout_height="35px" android:layout_width="0dip"></EditText>
</TableRow>
<TableRow>
<TextView android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Last Name:"/>
<EditText android:layout_marginRight="0dip"
android:id="@+id/userNameBox" android:layout_width="200px" android:layout_weight="1"
android:background="@android:drawable/editbox_background" android:maxLines="1"
android:layout_marginLeft="15dip" android:inputType="text"
android:layout_height="35px"></EditText>
</TableRow>
<TableRow>
<TextView android:id="@+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email:"/>
<EditText
android:id="@+id/userNameBox" android:layout_width="200px"
android:background="@android:drawable/editbox_background" android:layout_weight="1"
android:maxLines="1" android:layout_marginLeft="15dip" android:layout_marginRight="0dip"
android:inputType="text" android:layout_height="35px">
</EditText>
</TableRow>
<TableRow>
<TextView android:id="@+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mobile No:"/>
<EditText android:layout_marginRight="0dip"
android:id="@+id/userNameBox" android:layout_width="200px" android:layout_weight="1"
android:background="@android:drawable/editbox_background"
android:maxLines="1" android:layout_marginLeft="15dip"
android:inputType="text" android:layout_height="35px">
</EditText>
</TableRow>
<TableRow>
<Button
android:layout_height="wrap_content"
android:text="Register"
android:id="@+id/Button03"
android:padding="3dip"
android:layout_marginLeft="45dip"
android:layout_marginRight="90dip"
android:layout_marginTop="15dip"
android:layout_column="1"
android:layout_width="fill_parent"
android:layout_weight="1"/>
</TableRow>
</TableLayout>
flip3d.java
package com.animation;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TableLayout;
public class Flip3d extends Activity {
private LinearLayout layout01;
private TableLayout layout02;
private boolean isFirstLayout = true;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button newuser =(Button)findViewById(R.id.Button02);
layout01 = (LinearLayout) findViewById(R.id.Layout01);
layout02 = (TableLayout) findViewById(R.id.Layout02);
layout02.setVisibility(View.GONE);
newuser.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if (isFirstLayout) {
applyRotation(0, 90);
isFirstLayout = !isFirstLayout;
} else {
applyRotation(0, -90);
isFirstLayout = !isFirstLayout;
}
}
});
}
private void applyRotation(float start, float end) {
// Find the center of image
final float centerX = layout01.getWidth() / 2.0f;
final float centerY = layout01.getHeight() / 2.0f;
// Create a new 3D rotation with the supplied parameter
// The animation listener is used to trigger the next animation
final FlipAnimation rotation =
new FlipAnimation(start, end, centerX, centerY);
rotation.setDuration(500);
rotation.setFillAfter(true);
rotation.setInterpolator(new AccelerateInterpolator());
rotation.setAnimationListener(new DisplayNextView(isFirstLayout, layout01, layout02));
if (isFirstLayout)
{
layout01.startAnimation(rotation);
} else {
layout02.startAnimation(rotation);
}
}
public void setLayout01(LinearLayout layout01) {
this.layout01 = layout01;
}
public LinearLayout getLayout01() {
return layout01;
}
public void setLayout02(TableLayout layout02) {
this.layout02 = layout02;
}
public TableLayout getLayout02() {
return layout02;
}
}
Flipanimation.java
package com.animation;
import android.graphics.Camera;
import android.graphics.Matrix;
import android.view.animation.Animation;
import android.view.animation.Transformation;
public class FlipAnimation extends Animation {
private final float mFromDegrees;
private final float mToDegrees;
private final float mCenterX;
private final float mCenterY;
private Camera mCamera;
public FlipAnimation(float fromDegrees, float toDegrees,
float centerX, float centerY) {
mFromDegrees = fromDegrees;
mToDegrees = toDegrees;
mCenterX = centerX;
mCenterY = centerY;
}
@Override
public void initialize(int width, int height, int parentWidth, int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
mCamera = new Camera();
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
final float fromDegrees = mFromDegrees;
float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);
final float centerX = mCenterX;
final float centerY = mCenterY;
final Camera camera = mCamera;
final Matrix matrix = t.getMatrix();
camera.save();
camera.rotateY(degrees);
camera.getMatrix(matrix);
camera.restore();
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
}
}
Displaynextview.java
package com.animation;
import android.view.animation.Animation;
import android.widget.LinearLayout;
import android.widget.TableLayout;
public final class DisplayNextView implements Animation.AnimationListener {
private boolean mCurrentView;
LinearLayout layout01;
TableLayout layout02;
public DisplayNextView(boolean isFirstLayout, LinearLayout layout01,
TableLayout layout02) {
mCurrentView = isFirstLayout;
this.layout01 = layout01;
this.layout02 = layout02;
}
public void onAnimationStart(Animation animation) {
}
public void onAnimationEnd(Animation animation) {
layout01.post(new SwapViews(mCurrentView, layout01, layout02));
}
public void onAnimationRepeat(Animation animation) {
}
swapview.java
package com.animation;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import android.widget.LinearLayout;
import android.widget.TableLayout;
public final class SwapViews implements Runnable {
private boolean mIsFirstView;
LinearLayout layout01;
TableLayout layout02;
public SwapViews(boolean isFirstLayout, LinearLayout layout01, TableLayout layout02) {
mIsFirstView = isFirstLayout;
this.layout01 = layout01;
this.layout02 = layout02;
}
public void run() {
final float centerX = layout01.getWidth() / 2.0f;
final float centerY = layout02.getHeight() / 2.0f;
FlipAnimation rotation;
if (mIsFirstView) {
layout01.setVisibility(View.GONE);
layout02.setVisibility(View.VISIBLE);
layout02.requestFocus();
rotation = new FlipAnimation(-90, 0, centerX, centerY);
} else {
layout02.setVisibility(View.GONE);
layout01.setVisibility(View.VISIBLE);
layout01.requestFocus();
rotation = new FlipAnimation(90, 0, centerX, centerY);
}
rotation.setDuration(500);
rotation.setFillAfter(true);
rotation.setInterpolator(new DecelerateInterpolator());
if (mIsFirstView) {
layout02.startAnimation(rotation);
} else {
layout01.startAnimation(rotation);
}
}
}
翻转.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include android:id="@+id/notelist" layout="@layout/main" />
<include android:id="@+id/notelist" layout="@layout/register" />
</FrameLayout>
这些是 LOGCAT 中的错误
04-26 12:48:27.877:INFO/ActivityManager(57):为活动 com.animation/.Login 启动 proc com.animation:pid=294 uid=10047 gids={} 04-26 12:48:27.887: 调试/AndroidRuntime(276): 关闭虚拟机 04-26 12:48:27.947:调试/jdwp(276):adbd 已断开连接 04-26 12:48:27.988: INFO/AndroidRuntime(276): 注意: 附加线程 'Binder Thread #3' 失败 04-26 12:48:28.647: 调试/AndroidRuntime(294): 关闭虚拟机 04-26 12:48:28.657: WARN/dalvikvm(294): threadid=1: 线程以未捕获的异常退出(组=0x4001d800) 04-26 12:48:28.697: 错误/AndroidRuntime(294): 致命异常: main 04-26 12:48:28.697: 错误/AndroidRuntime(294): java.lang.RuntimeException: 无法实例化活动 ComponentInfo{com.animation/com.animation.Login}: java.lang.ClassNotFoundException: com.animation.Login在加载器 dalvik.system.PathClassLoader[/data/app/com.animation-1.apk] 04-26 12:48:28.697: 错误/AndroidRuntime(294): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585) 04-26 12:48:28.697: 错误/AndroidRuntime(294): 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 04-26 12:48:28.697: 错误/AndroidRuntime(294): 在 android.app.ActivityThread.access$2300(ActivityThread.java:125) 04-26 12:48:28.697: 错误/AndroidRuntime(294): 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 04-26 12:48:28.697: 错误/AndroidRuntime(294): 在 android.os.Handler.dispatchMessage(Handler.java:99) 04-26 12:48:28.697: 错误/AndroidRuntime(294): 在 android.os.Looper.loop(Looper.java:123) 04-26 12:48:28.697: 错误/AndroidRuntime(294): 在 android.app.ActivityThread.main(ActivityThread.java:4627) 04-26 12:48:28.697: 错误/AndroidRuntime(294): 在 java.lang.reflect.Method.invokeNative(Native Method) 04-26 12:48:28.697: 错误/AndroidRuntime(294): 在 java.lang.reflect.Method.invoke(Method.java:521) 04-26 12:48:28.697: 错误/AndroidRuntime(294): 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 04-26 12:48:28.697: 错误/AndroidRuntime(294): 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 04-26 12:48:28.697: 错误/AndroidRuntime(294): at dalvik.system.NativeStart.main(Native Method) 04-26 12:48:28.697: 错误/AndroidRuntime(294): 由: java.lang.ClassNotFoundException: com.animation.Login in loader dalvik.system.PathClassLoader[/data/app/com.animation-1.apk ] 04-26 12:48:28.697: 错误/AndroidRuntime(294): 在 dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243) 04-26 12:48:28.697: 错误/AndroidRuntime(294): 在 java.lang.ClassLoader.loadClass(ClassLoader.java:573) 04-26 12:48:28.697: 错误/AndroidRuntime(294): 在 java.lang.ClassLoader.loadClass(ClassLoader.java:532) 04-26 12:48:28.697: 错误/AndroidRuntime(294): 在 android.app.Instrumentation.newActivity(Instrumentation.java:1021) 04-26 12:48:28.697: 错误/AndroidRuntime(294): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577) 04-26 12:48:28.697: 错误/AndroidRuntime(294): ... 11 更多 04-26 12:48:28.757: WARN/ActivityManager(57): 强制完成活动 com.animation/.Login 04-26 12:48:29.267: WARN/ActivityManager(57): HistoryRecord{43fe6f90 com.animation/.Login} 的活动暂停超时 04-26 12:48:39.376: WARN/ActivityManager(57): HistoryRecord{43fe6f90 com.animation/.Login} 的活动销毁超时 04-26 12:48:44.548:调试/KeyguardViewMediator(57):pokeWakelock(5000) 04-26 12:48:44.658:调试/KeyguardViewMediator(57):pokeWakelock(5000) 04-26 12:48:44.888: WARN/WindowManager(57): No window to dispatch pointer action 1 04-26 12:48:44.958: INFO/ARMAssembler(57): 生成扫描线__00000177:03515104_00001001_00000000 [91 ipp] (114 ins) at [0x360da0:0x360f68] in 5876460 ns 04-26 12:48:45.018: INFO/ARMAssembler(57): 生成扫描线__00000077:03515104_00000000_00000000 [33 ipp] (47 ins) at [0x360f70:0x36102c] in 606224 ns 04-26 12:48:49.278: INFO/Process(294): 发送信号。 PID:294 SIG:9 04-26 12:48:49.288: INFO/ActivityManager(57): Process com.animation (pid 294) 已经死亡。
【问题讨论】:
标签: android android-layout flip