package com.example.testpicture;
import android.animation.Keyframe;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.BounceInterpolator;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.example.model.ParabolaAlgorithm;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout layout = new LinearLayout(this);
layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
layout.setPadding(0, 100, 0, 0);
layout.setOrientation(LinearLayout.VERTICAL);
final ImageView imageView = new ImageView(this);
imageView.setImageResource(R.drawable.face_0_063);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
params.setMargins(0, 200, 0, 0);
imageView.setLayoutParams(params);
final TextView textView1 = new TextView(this);
textView1.setText("第一坐标点(空格区分x y)");
layout.addView(textView1);
final EditText editText1 = new EditText(this);
editText1.setPadding(20, 10, 20, 10);
editText1.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
editText1.setHint("第一坐标点(空格区分x y)");
editText1.setText("6 15");
editText1.setSingleLine();
editText1.setInputType(EditorInfo.TYPE_CLASS_NUMBER);
layout.addView(editText1);
final TextView textView2 = new TextView(this);
textView2.setText("第二坐标点(空格区分x y)");
layout.addView(textView2);
final EditText editText2 = new EditText(this);
editText2.setHint("第二坐标点(空格区分x y)");
editText2.setPadding(20, 10, 20, 10);
editText2.setSingleLine();
editText2.setInputType(EditorInfo.TYPE_CLASS_NUMBER);
editText2.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
editText2.setText("50 70");
layout.addView(editText2);
final TextView textView3 = new TextView(this);
textView3.setText("第三坐标点(空格区分x y)");
layout.addView(textView3);
final EditText editText3 = new EditText(this);
editText3.setHint("第三坐标点(空格区分x y)");
editText3.setPadding(20, 10, 20, 10);
editText3.setSingleLine();
editText3.setInputType(EditorInfo.TYPE_CLASS_NUMBER);
editText3.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
editText3.setText("120 -100");
layout.addView(editText3);
Button button = new Button(this);
button.setText("test");
button.setPadding(20, 10, 20, 10);
button.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String[] string1 = editText1.getText().toString().split(" ");
String[] string2 = editText2.getText().toString().split(" ");
String[] string3 = editText3.getText().toString().split(" ");
final float[][] points = { { Float.valueOf(string1[0]), Float.valueOf(string1[1]) },
{ Float.valueOf(string2[0]), Float.valueOf(string2[1]) },
{ Float.valueOf(string3[0]), Float.valueOf(string3[1]) } };
float[] value = ParabolaAlgorithm.calculate(points);
a = value[0];
b = value[1];
c = value[2];
count = (int)(points[2][0] - points[0][0]);
startAnimation(imageView);
}
});
layout.addView(button);
layout.addView(imageView);
setContentView(layout);
}
int count = 120;
/**
* 要start 动画的那张图片的ImageView
*
* @param imageView
*/
private void startAnimation(final ImageView imageView) {
Keyframe[] keyframes = new Keyframe[count];
final float keyStep = 1f / (float) count;
float key = keyStep;
for (int i = 0; i < count; ++i) {
keyframes[i] = Keyframe.ofFloat(key, i + 1);
key += keyStep;
}
PropertyValuesHolder pvhX = PropertyValuesHolder.ofKeyframe("translationX", keyframes);
key = keyStep;
for (int i = 0; i < count; ++i) {
keyframes[i] = Keyframe.ofFloat(key, -getY(i + 1));
key += keyStep;
}
PropertyValuesHolder pvhY = PropertyValuesHolder.ofKeyframe("translationY", keyframes);
ObjectAnimator yxBouncer = ObjectAnimator.ofPropertyValuesHolder(imageView, pvhY, pvhX).setDuration(1500);
yxBouncer.setInterpolator(new BounceInterpolator());
yxBouncer.start();
}
float a = 0f, b = 0f, c = 0f;
/**
* 这里是根据三个坐标点{(0,0),(300,0),(150,300)}计算出来的抛物线方程
*
* @param x
* @return
*/
private float getY(float x) {
return a * x * x + b * x + c;
}
}
Android 抛物线动画
5星 · 超过95%的资源 需积分: 10 133 浏览量
2015-11-10
18:46:29
上传
评论 1
收藏 2KB ZIP 举报
freesonfish
- 粉丝: 130
- 资源: 7
最新资源
- 常用工具配置docker,elasticsearch,minio,nfs,nginx,tippercane,vsftp
- 基于IIC接口E2PROM(AT24C64)芯片FPGA读写VERILOG 设计源码+仿真激励文件.zip
- 基于FPGA深度学习的Block 模块方案实战,适合FPGA初学者
- 20225T9050袁凤(1).py
- Rsa算法详解.docx
- Youren Shang InClassQuiz.ipynb
- code-qat.zip
- usb-serial-for-android
- drools决策表示例Excel文件
- AD5724芯片FPGA Verilog驱动源码+4通道12bit位宽的DAC芯片AD5724技术手册.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
前往页