带有Android Things的动荡动画

时间:2018-10-13 14:11:59

标签: java android animation android-emulator android-things

我一直在研究基于Android Things的智能镜像软件。目前,它只是一个模型。在将“翻译动画”添加到小部件后,在纵向模式下它们显得非常缓慢且不稳定:

Activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
tools:context=".MainActivity">

<TextView
    android:id="@+id/date"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignStart="@+id/time"
    android:layout_below="@+id/time"
    android:text="Saturday, 13 October"
    android:textColor="@android:color/white"
    android:textSize="25sp" />

<TextView
    android:id="@+id/time"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_marginStart="44dp"
    android:layout_marginTop="62dp"
    android:text="09:41"
    android:textColor="@android:color/white"
    android:textSize="70sp" />

<ImageView
    android:id="@+id/weatherTypeImg"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignStart="@+id/date"
    android:layout_marginTop="233dp"
    android:src="@drawable/ic_wb_sunny_black_24dp" />

<TextView
    android:id="@+id/temp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignStart="@+id/date"
    android:layout_below="@+id/weatherTypeImg"
    android:text="28°"
    android:textColor="@android:color/white"
    android:textSize="20sp" />

<TextView
    android:id="@+id/weatherType"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignStart="@+id/date"
    android:layout_below="@+id/temp"
    android:fontFamily="sans-serif-condensed"
    android:text="Sunny"
    android:textColor="@android:color/white"
    android:textSize="14sp" />

</RelativeLayout>'

MainActivity.java:

package com.ladiesman6969.SmartMirror;


import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.Handler;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.Timer;
import java.util.TimerTask;


public class MainActivity extends Activity {

TextView date;
TextView time;
TextView temp;
ImageView weatherTypeImg;
TextView weatherType;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    getActionBar().hide();

    date = findViewById(R.id.date);
    time = findViewById(R.id.time);
    temp = findViewById(R.id.temp);
    weatherTypeImg = findViewById(R.id.weatherTypeImg);
    weatherType = findViewById(R.id.weatherType);


    TranslateAnimation timeStartAnimation = new TranslateAnimation(-100,0,0,0);
    timeStartAnimation.setInterpolator(new LinearInterpolator());
    timeStartAnimation.setStartOffset(500);
    timeStartAnimation.setDuration(500);

    TranslateAnimation dateStartAnimation = new TranslateAnimation(-100,0,0,0);
    dateStartAnimation.setInterpolator(new LinearInterpolator());
    dateStartAnimation.setStartOffset(600);
    dateStartAnimation.setDuration(500);

    TranslateAnimation weatherImageStartAnimation = new TranslateAnimation(-250,0,0,0);
    weatherImageStartAnimation.setInterpolator(new LinearInterpolator());
    weatherImageStartAnimation.setStartOffset(700);
    weatherImageStartAnimation.setDuration(500);

    TranslateAnimation temperatureStartAnimation = new TranslateAnimation(-250,0,0,0);
    temperatureStartAnimation.setInterpolator(new LinearInterpolator());
    temperatureStartAnimation.setStartOffset(800);
    temperatureStartAnimation.setDuration(500);

    TranslateAnimation weatherTypeStartAnimation = new TranslateAnimation(-250,0,0,0);
    weatherTypeStartAnimation.setInterpolator(new LinearInterpolator());
    weatherTypeStartAnimation.setStartOffset(900);
    weatherTypeStartAnimation.setDuration(500);

    date.startAnimation(dateStartAnimation);
    time.startAnimation(timeStartAnimation);
    weatherTypeImg.startAnimation(weatherImageStartAnimation);
    temp.setAnimation(temperatureStartAnimation);
    weatherType.setAnimation(weatherTypeStartAnimation);
  }
}

当我通过添加在Android模拟器上运行此代码时,它运行起来绝对顺滑。

当我在具有最新Android Things Build(1.0.5)的Raspberry Pi 3 Model B上运行此代码时,它在横向模式下运行良好。

令人惊讶的是,当我以纵向为方向运行此代码时,动画非常 cr脚

这里有一个小的video供您参考。

预先感谢:)

0 个答案:

没有答案