ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

AutoTextView实现文字自动翻转效果,android音乐播放器实验报告

2021-12-22 15:33:35  阅读:135  来源: 互联网

标签:AutoTextView void float private public new android 实验报告 final


}

private Rotate3dAnimation createAnim(float start, float end, boolean turnIn, boolean turnUp) {

final Rotate3dAnimation rotation = new Rotate3dAnimation(start, end, turnIn, turnUp);

rotation.setDuration(800);

rotation.setFillAfter(false);

rotation.setInterpolator(new AccelerateInterpolator());

return rotation;

}

//这里返回的TextView,就是我们看到的View

@Override

public View makeView() {

TextView t = new TextView(mContext);

// t.setGravity(Gravity.CENTER);

t.setTextSize(mHeight);

// t.setTextColor(Resources.getSystem().getColor(android.R.color.black));

t.setTextColor(mContext.getResources().getColor(R.color.white));

t.setTextSize(13);

// t.setGravity(Gravity.CENTER_VERTICAL);

t.setPadding(0,15

《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》

【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享

,0,15);

t.setMaxLines(1);

t.setEllipsize(TextUtils.TruncateAt.END);

return t;

}

//定义动作,向下滚动翻页

public void previous() {

if (getInAnimation() != mInDown) {

setInAnimation(mInDown);

}

if (getOutAnimation() != mOutDown) {

setOutAnimation(mOutDown);

}

}

//定义动作,向上滚动翻页

public void next() {

if (getInAnimation() != mInUp) {

setInAnimation(mInUp);

}

if (getOutAnimation() != mOutUp) {

setOutAnimation(mOutUp);

}

}

class Rotate3dAnimation extends Animation {

private final float mFromDegrees;

private final float mToDegrees;

private float mCenterX;

private float mCenterY;

private final boolean mTurnIn;

private final boolean mTurnUp;

private Camera mCamera;

public Rotate3dAnimation(float fromDegrees, float toDegrees, boolean turnIn, boolean turnUp) {

mFromDegrees = fromDegrees;

mToDegrees = toDegrees;

mTurnIn = turnIn;

mTurnUp = turnUp;

}

@Override

public void initialize(int width, int height, int parentWidth, int parentHeight) {

super.initialize(width, height, parentWidth, parentHeight);

mCamera = new Camera();

mCenterY = getHeight() / 2;

mCenterX = getWidth() / 2;

}

@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 int derection = mTurnUp ? 1 : -1;

final Matrix matrix = t.getMatrix();

camera.save();

if (mTurnIn) {

camera.translate(0.0f, derection * mCenterY * (interpolatedTime - 1.0f), 0.0f);

} else {

camera.translate(0.0f, derection * mCenterY * (interpolatedTime), 0.0f);

}

camera.rotateX(degrees);

camera.getMatrix(matrix);

camera.restore();

matrix.preTranslate(-centerX, -centerY);

matrix.postTranslate(centerX, centerY);

}

}

}

attrs.xml

xml

<com.xx.xx.view.AutoTextView

android:id="@+id/atv_auto_qy"

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:layout_marginTop="@dimen/margin_5" />

activity

private void showQyInfo() {

// qyPowers.clear();

isShowQyView = true;

mQyInfoView.setVisibility(View.VISIBLE);

if(timer == null){

String[] qyinfo = context.getResources().getStringArray(R.array.qy_power);

qyPowers = Arrays.asList(qyinfo);

timer = new Timer();

timer.schedule(timerTask, 100, 3000);

powerPosition = 0;

}

}

//计时

TimerTask timerTask = new TimerTask() {

@Override

public void run() {

if(isShowQyView) {

Message message = new Message();

message.what = 0x001;

handler.sendMessage(message);

}

}

};

final Handler handler = new Handler() {

@Override

public void handleMessage(Message msg) {

switch (msg.what) {

case 0x001:

atvQy.next();

atvQy.setText(qyPowers.get(powerPosition));

powerPosition ++;

powerPosition = powerPosition % 3;

}

}

};

strings.xml

标签:AutoTextView,void,float,private,public,new,android,实验报告,final
来源: https://blog.csdn.net/m0_65511857/article/details/122086673

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有