0

私はアンドロイドの初心者です。Googleで少し検索した後、アニメーションプログラムを試してみましたが、エミュレータで強制的に閉じて、プロジェクトの実行中に何も表示されませんでした

2 つのレイアウト (xml ファイル)、つまり signin.xml と register.xml に対して反転/回転効果を持たせたいと考えています。signin.xml の new-user ボタンを 1 回クリックして、レイアウトを register.xml に変更したい

私は 2 つのレイアウトを採用し、実装を試みました。つまり、リニア レイアウトとテーブル レイアウトです。それは私が従った正しい手順ですか

試用用に単一のボタンを追加しましたが、機能していません。このコードの問題点を知りたいです

エラーは発生しませんが、実行中にエミュレータに問題が発生します。

誰か助けてください...ありがとう!

これらの r 私の 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>

register.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);

}

}

次のビューを表示します。

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 のエラーです

animation/.Login} 04-26 12:48:44.548: DEBUG/KeyguardViewMediator(57): pokeWakelock(5000) 04-26 12:48:44.658: DEBUG/KeyguardViewMediator(57): pokeWakelock(5000) 04-26 12: 48:44.888: WARN/WindowManager(57): ポインター アクション 1 をディスパッチするウィンドウがありません 04-26 12:48:44.958: INFO/ARMAssembler(57): 生成された scanline__00000177:03515104_00001001_00000000 [91 ipp] (114 ins) at [0x360da0: 0x360F68] 5876460 NS 04-26 12:48:45.018:INFO/ARMASSEMBLER(57):生成されたScanline__00000077:03515104_000000000000000000 [33 IPP](47 INS) : 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): 生成された scanline__00000177:03515104_00001001_00000000 [ 91 ipp ](114 Ins)at [0x360Da0:0x360f68] in 5876460 ns 04-26 12:48:45.018:info/armassembler(57):生成されたscanline__00000077:03515104_00000000_0000000000000000000000000000 ns 04-26 12:48:49.278: 情報/プロセス (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): 生成された scanline__00000177:03515104_00001001_00000000 [ 91 ipp ](114 Ins)at [0x360Da0:0x360f68] in 5876460 ns 04-26 12:48:45.018:info/armassembler(57):生成されたscanline__00000077:03515104_00000000_0000000000000000000000000000 ns 04-26 12:48:49.278: 情報/プロセス (294): 信号を送信しています。PID: 294 SIG: 9 04-26 12:48:49.288: INFO/ActivityManager(57): プロセス com.animation (pid 294) が停止しました。生成された scanline__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) が停止しました。生成された scanline__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

次に、include タグを使用してそれらを含める代わりに、main.xml と register.xml の実際のレイアウト コンテンツを flip.xml 自体にコピーします。エミュレータはこの方法でレイアウトの組み込みを処理できないようです。

于 2011-08-09T17:33:32.270 に答える