美好的一天,我刚开始玩android studio,我在任何布局或场景中都坚持应用转换。 我已完全按照本网站中的程序进行操作
这是我的.java代码:
package com.ebookfrenzy.transitiondemo;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.transition.ChangeBounds;
import android.transition.Transition;
import android.transition.TransitionManager;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.BounceInterpolator;
import android.widget.RelativeLayout;
public class TransitionDemoActivity extends ActionBarActivity {
ViewGroup myLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_transition_demo);
myLayout = (ViewGroup) findViewById(R.id.myLayout);
myLayout.setOnTouchListener(
new RelativeLayout.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent m) {
handleTouch();
return true;
}
}
);
}
public void handleTouch() {
View view = findViewById(R.id.myButton1);
Transition changeBounds = new ChangeBounds();
changeBounds.setDuration(3000);
changeBounds.setInterpolator (new BounceInterpolator());
TransitionManager.beginDelayedTransition(myLayout,changeBounds);
TransitionManager.beginDelayedTransition(myLayout);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
params.width = 500;
params.height = 350;
view.setLayoutParams(params);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_transition_demo, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
这是我的.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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".TransitionDemoActivity"
android:id="@+id/myLayout">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/myButton1"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
此程序的目的是将按钮从左上角移动到右下角,然后调整大小。该教程解释说应该有一个“慢”的“慢”。触摸背景布局后的动画或过渡。但它是通往不稳定的方式。 (它确实移动并调整大小,完全没有错误)
尝试了涉及Transition的其他项目,例如: http://code.tutsplus.com/tutorials/an-introduction-to-android-transitions--cms-21640
但应用程序停止了工作。
我的程序(上图)实际上是错误的吗?或者它是正确的,有一些可能的内部错误? 请原谅我新手的问题,如果我在问第一个问题时犯了错误,请通知我。
这是我的logcat(详细):
02-10 08:33:16.921 30478-30478/com.ebookfrenzy.transitiondemo D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
02-10 08:33:16.981 30478-30478/com.ebookfrenzy.transitiondemo I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:385>: EGL 1.4 QUALCOMM build: ()
OpenGL ES Shader Compiler Version: E031.24.00.02
Build Date: 01/20/14 Mon
Local Branch: PMH2-KK_3.5-RB1-AU61-554722-586267-set2
Remote Branch:
Local Patches:
Reconstruct Branch:
02-10 08:33:17.011 30478-30478/com.ebookfrenzy.transitiondemo D/OpenGLRenderer﹕ Enabling debug mode 0
02-10 08:33:17.061 30478-30478/com.ebookfrenzy.transitiondemo I/ActivityManager﹕ Timeline: Activity_idle id: android.os.BinderProxy@428b96c8 time:82126736
02-10 08:34:24.061 30478-30478/com.ebookfrenzy.transitiondemo I/ViewRootImpl﹕ ViewRoot's Touch Event : Touch Down
02-10 08:34:24.091 30478-30478/com.ebookfrenzy.transitiondemo I/ViewRootImpl﹕ ViewRoot's Touch Event : Touch UP
提前致谢。