0

我是安卓新手。在谷歌搜索了一下后,我尝试了一个动画程序并在模拟器中强制关闭,并且在运行项目时没有显示任何东西

我想为两个布局(xml 文件)(即 signin.xml 和 register.xml)设置翻转/翻转效果。通过单击 signin.xml 中的新用户按钮,我想将布局转换为 register.xml

我采用了两种布局并尝试实现,即线性和表格布局。我遵循的程序是否正确

我添加了单个按钮进行试用,但它不起作用,我想知道这段代码有什么问题

我没有收到任何错误,但运行时模拟器出现问题。

请有人帮助我,...谢谢!

这些是我的 xml 文件

主要的.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>

翻转3d.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;
}
}

翻转动画.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) {
}

交换视图.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>

这些 r LOGCAT 中的错误

动画/.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):没有窗口可调度指针操作 1 04-26 12:48:44.958:INFO/ARMAssembler(57):生成的扫描线__00000177:03515104_00001001_00000000 [91 ipp](114 英寸)在 [0x360da0: 0x360F68]在5876460 NS 04-26 12:48:45.018:INFO / ARMASSEMBLER(57):生成的SCANLINE__00000077:03515104_0000000000_00000000 [IPP](47 INS)在[0x360F70:0x36102C]中,在606224 NS 04-26 12:48:49.278 : INFO/Process(294): 发送信号。PID:294 SIG:9 04-26 12:48:49.288:INFO/ActivityManager(57):进程 com.animation (pid 294) 已死亡。pokeWakelock(5000) 04-26 12:48:44.888: WARN/WindowManager(57): 没有窗口来调度指针操作 1 04-26 12:48:44.958: INFO/ARMAssembler(57): 生成扫描线__00000177:03515104_00001001_00000000 [91 ipp ](114 INS)在[0x360DA0:0x360F68]中,在5876460 NS 04-26 12:48:45.018:INFO / ARMASSEMBLER(57):生成的SCANLINE__00000077:03515104_00000000_00000000 [IPP](47 INS)在[0x360F70:0x36102C]在606224 ns 04-26 12:48:49.278: INFO/Process(294): 发送信号。PID:294 SIG:9 04-26 12:48:49.288:INFO/ActivityManager(57):进程 com.animation (pid 294) 已死亡。pokeWakelock(5000) 04-26 12:48:44.888: WARN/WindowManager(57): 没有窗口来调度指针操作 1 04-26 12:48:44.958: INFO/ARMAssembler(57): 生成扫描线__00000177:03515104_00001001_00000000 [91 ipp ](114 INS)在[0x360DA0:0x360F68]中,在5876460 NS 04-26 12:48:45.018:INFO / ARMASSEMBLER(57):生成的SCANLINE__00000077:03515104_00000000_00000000 [IPP](47 INS)在[0x360F70:0x36102C]在606224 ns 04-26 12:48:49.278: INFO/Process(294): 发送信号。PID:294 SIG:9 04-26 12:48:49.288:INFO/ActivityManager(57):进程 com.animation (pid 294) 已死亡。生成扫描线__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):进程 com.animation (pid 294) 已死亡。生成扫描线__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):进程 com.animation (pid 294) 已死亡。

4

1 回答 1

0

我已经检查了您在模拟器上的代码及其现在的工作。您必须首先更改 Flip3d.java 中包含的布局名称

setContentView(R.id.flip); //currenlty its R.id.main

然后将 main.xml 和 register.xml 的实际布局内容复制到flip.xml itslef 中,而不是使用include 标记包含它们。似乎模拟器无法以这种方式处理布局包含。

于 2011-08-09T17:33:32.270 回答