98.s1-插补器原理实现文本框的抖动

以输入号码归属地为例,当输入正确的时候没有反应,当输入的号码归属地为空的时候号码框会抖动

插补器:interpolator(循环插补器cycleInterpolator)Interpolator可以限定一个动画的变化率。 这样的话,可以对基本的动画效果(比如透明、缩放、位移、旋转)进行加速、减速、重复等。文本框的抖动就是样式不断的重复,产生的效果。插补器主要有一下一些

实现文本框的抖动范例

res/anim目录下面分别放两个文件一个是shake.xml和一个cycle_7.xml的文件,前者是动画的效果,后面似乎引入的插补器

res/anim/shake.xml动画文件

<?xml version="1.0" encoding="utf-8"?>
<!--
     Copyright (C) 2007 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at
  
          http://www.apache.org/licenses/LICENSE-2.0
  
     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1000"
    android:fromXDelta="0"
    android:interpolator="@anim/cycle_7"
    android:toXDelta="10" />

res/anim/cycle_7.xml插补器

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2007 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at
  
          http://www.apache.org/licenses/LICENSE-2.0
  
     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions anda
     limitations under the License.
-->

<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android" android:cycles="7" />

逻辑代码

package com.ldw.safe.Activity;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.EditText;
import android.widget.TextView;

import com.ldw.safe.R;
import com.ldw.safe.db.dao.AddressDao;

/*
 * 归属地穿页面
 */
public class AddressActivity extends Activity {

	private EditText etNumber;
	private TextView tvResult;
	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_address);
        
        etNumber = (EditText) findViewById(R.id.et_number);
        tvResult = (TextView) findViewById(R.id.tv_result);
        
        //监听EditText的实时变化,输入数字,edit会发生变化
        etNumber.addTextChangedListener(new TextWatcher(){

        	//发生变化前的回调函数
			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
				// TODO Auto-generated method stub
				
			}

			//发生变化的回调函数
			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
				//监听文本的实时变化
				String address = AddressDao.getAddress(s.toString());
				tvResult.setText(address);
				
			}

			//发生变化以后的回调函数
			@Override
			public void afterTextChanged(Editable s) {
				// TODO Auto-generated method stub
				
			}
        	
        });
	}
	
	/*
	 * 开始查询
	 */
	public void query(View v){
		String number = etNumber.getText().toString().trim();
		if(!TextUtils.isEmpty(number)){
			String address = AddressDao.getAddress(number);
			tvResult.setText(address);
		}else{
			//没有填东西的时候会震动,使用插补器实现
			Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
			etNumber.startAnimation(shake);
		}
	}
		
		
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 圆弧插补是指将圆弧转换为若干个线段或点,并在 STM32 上实现它。下面是一个简单的实现方法: 1. 计算圆弧上的点:使用极坐标系中的极角和极径来确定圆弧上的点。 2. 将极坐标转换为直角坐标:使用极坐标公式将极坐标转换为直角坐标。 3. 使用点进行插补:使用这些直角坐标点实现圆弧插补。 以下是一个简单的 C 语言代码实现: ``` #include <math.h> #define PI 3.14159265 void arc_interpolation(float center_x, float center_y, float radius, float start_angle, float end_angle, float step_size) { float angle; for (angle = start_angle; angle < end_angle; angle += step_size) { float x = center_x + radius * cos(angle * PI / 180.0); float y = center_y + radius * sin(angle * PI / 180.0); // 插补代码 } } ``` 这是一个简单的圆弧插补代码,可以作为实现圆弧插补的参考。实际应用中可能需要对代码进行更多的修改和优化。 ### 回答2: 要实现在STM32中进行圆弧插补,可以使用C语言编写代码来实现。以下是一个简单的伪代码示例: 1. 定义圆弧插补所需的变量: - 起始点(startPointX,startPointY) - 终点(endPointX,endPointY) - 圆心(centerX,centerY) - 半径(radius) - 插补步长(step) 2. 计算圆心的坐标: - centerX = (startPointX + endPointX) / 2 - centerY = (startPointY + endPointY) / 2 3. 计算弧度: - angle = atan2(endPointY - centerY, endPointX - centerX) 4. 根据半径和step计算需要插补的次数: - numSteps = 2 * PI * radius / step 5. 循环进行插补: - for (i = 0; i <= numSteps; i++) { - currentAngle = angle * i / numSteps - currentX = centerX + radius * cos(currentAngle) - currentY = centerY + radius * sin(currentAngle) - 将(currentX, currentY)作为坐标发送到驱动器或控制器 } 以上是一个简单的圆弧插补C语言代码示例。实际上,要实现更复杂的圆弧插补,可能需要考虑速度控制、加速度控制、角度转换等问题。具体的实现代码可能因应用的不同而有所变化。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值