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

}

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

上一篇:java常见面试题


下一篇:带你快速看完9.8分神作《Effective Java》—— 类和接口篇